From: Kefu Chai Date: Sun, 4 Apr 2021 02:02:55 +0000 (+0800) Subject: pybind/mgr/mgr_util: fix typing annotation X-Git-Tag: v16.2.2~26^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F40630%2Fhead;p=ceph.git 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) --- diff --git a/src/pybind/mgr/mgr_util.py b/src/pybind/mgr/mgr_util.py index be0342351888..75d5b5c38eb4 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):