diff --git a/lib/locking.py b/lib/locking.py index 74f170241ec9308fbaebfb17e1cd5f11c099e9c6..014b378509b01057078b579858ad38e84887d530 100644 --- a/lib/locking.py +++ b/lib/locking.py @@ -47,6 +47,10 @@ _DELETED_TEXT = "deleted" _DEFAULT_PRIORITY = 0 +#: Minimum timeout required to consider scheduling a pending acquisition +#: (seconds) +_LOCK_ACQUIRE_MIN_TIMEOUT = (1.0 / 1000) + def ssynchronized(mylock, shared=0): """Shared Synchronization decorator. @@ -662,6 +666,12 @@ class SharedLock(object): self.__do_acquire(shared) return True + # The lock couldn't be acquired right away, so if a timeout is given and is + # considered too short, return right away as scheduling a pending + # acquisition is quite expensive + if timeout is not None and timeout < _LOCK_ACQUIRE_MIN_TIMEOUT: + return False + prioqueue = self.__pending_by_prio.get(priority, None) if shared: