From fcfc1e8998b8fcfece5c434115cd1686cc7d041b Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Thu, 20 Jun 2024 17:57:54 +0300 Subject: [PATCH] Support a more granular distributed lock wait --- apiserver/sync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apiserver/sync.py b/apiserver/sync.py index 42f445f..de96adc 100644 --- a/apiserver/sync.py +++ b/apiserver/sync.py @@ -21,7 +21,7 @@ def distributed_lock(name: str, timeout: int, max_wait: int = 0): max_wait = max_wait or timeout * 2 pid = os.getpid() while _redis.set(lock_name, value=pid, ex=timeout, nx=True) is None: - sleep(1) + sleep(0.1) if time.time() - start > max_wait: holder = _redis.get(lock_name) raise Exception(f"Could not acquire {name} lock for {max_wait} seconds. The lock is hold by {holder}")