From 85c380c382674600ab563082f05d801ef01081c4 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 4 Apr 2021 10:02:55 +0800 Subject: [PATCH] pybind/mgr/mgr_util: fix typing annotation and refactor lock_timeout_log() a little bit to drop `locked`. Signed-off-by: Kefu Chai (cherry picked from commit 5e1c42082e7076ae6f5264d6005029690588e5aa) --- src/pybind/mgr/mgr_util.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/pybind/mgr/mgr_util.py b/src/pybind/mgr/mgr_util.py index be03423518882..75d5b5c38eb43 100644 --- a/src/pybind/mgr/mgr_util.py +++ b/src/pybind/mgr/mgr_util.py @@ -74,24 +74,22 @@ class RTimer(Timer): raise @contextlib.contextmanager -def lock_timeout_log(lock: Lock, timeout: int = 5) -> Iterator[bool]: +def lock_timeout_log(lock: Lock, timeout: int = 5) -> Iterator[None]: start = time.time() WARN_AFTER = 30 warned = False - locked = False while True: logger.debug("locking {} with {} timeout".format(lock, timeout)) - locked = lock.acquire(timeout=timeout) - if locked: + if lock.acquire(timeout=timeout): logger.debug("locked {}".format(lock)) + yield + lock.release() break now = time.time() if not warned and now - start > WARN_AFTER: logger.info("possible deadlock acquiring {}".format(lock)) warned = True - yield - if locked: - lock.release() + class CephfsConnectionPool(object): class Connection(object): -- 2.39.5