Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pottery/redlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class Redlock(Scripts, Primitive):
'num_extensions',
'context_manager_blocking',
'context_manager_timeout',
'retry_delay',
'_uuid',
'_extension_num',
)
Expand All @@ -240,6 +241,7 @@ def __init__(self,
num_extensions: int = _NUM_EXTENSIONS,
context_manager_blocking: bool = True,
context_manager_timeout: float = -1,
retry_delay: float = _RETRY_DELAY,
) -> None:
'''Initialize a Redlock.

Expand All @@ -259,6 +261,8 @@ def __init__(self,
context_manager_timeout -- if context_manager_blocking, how long to
wait when acquiring before giving up and raising the
QuorumNotAchieved exception
retry_delay -- the upper bound of how long to block before attempting
to re-acquire the lock
'''
if not context_manager_blocking and context_manager_timeout != -1:
raise ValueError("can't specify a timeout for a non-blocking call")
Expand All @@ -272,6 +276,7 @@ def __init__(self,
self.num_extensions = num_extensions
self.context_manager_blocking = context_manager_blocking
self.context_manager_timeout = context_manager_timeout
self.retry_delay = retry_delay
self._uuid = ''
self._extension_num = 0

Expand Down Expand Up @@ -420,7 +425,7 @@ def acquire(self,
self.__log_time_enqueued(timer, acquired=True)
return True
enqueued = True
delay = random.uniform(0, self._RETRY_DELAY) # nosec
delay = random.uniform(0, self.retry_delay) # nosec
time.sleep(delay)
if enqueued: # pragma: no cover
self.__log_time_enqueued(timer, acquired=False)
Expand Down