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