]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/mgr_util: fix typing annotation 40630/head
authorKefu Chai <kchai@redhat.com>
Sun, 4 Apr 2021 02:02:55 +0000 (10:02 +0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Thu, 22 Apr 2021 16:17:41 +0000 (09:17 -0700)
and refactor lock_timeout_log() a little bit to drop `locked`.

Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 5e1c42082e7076ae6f5264d6005029690588e5aa)

src/pybind/mgr/mgr_util.py

index be034235188825195b9fcb0cea0f0b03f57449f7..75d5b5c38eb433b345208d081909d7909bc592bd 100644 (file)
@@ -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):