Skip to content

Commit 87fe12f

Browse files
author
Joshua Harlow
committed
Fix semaphore usage
The semaphore should be passing the blocking argument to the underlying lock that is used (so it is non-blocking as well) and it should also be passing the timeout as well. The non-blocking result should also not add a watch that will later attempt to get the least (another call to acquire should be used instead, or the blocking mode should be used instead).
1 parent d780c64 commit 87fe12f

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

kazoo/recipe/lock.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,11 @@ def _inner_acquire(self, blocking, timeout=None):
448448
if self.client.exists(self.create_path):
449449
return True
450450

451-
with self.client.Lock(self.lock_path, self.data):
451+
lock = self.client.Lock(self.lock_path, self.data)
452+
gotten = lock.acquire(blocking=blocking, timeout=timeout)
453+
if not gotten:
454+
return False
455+
try:
452456
while True:
453457
self.wake_event.clear()
454458

@@ -465,10 +469,9 @@ def _inner_acquire(self, blocking, timeout=None):
465469
"Failed to acquire semaphore on %s "
466470
"after %s seconds" % (self.path, timeout))
467471
else:
468-
# If not blocking, register another watch that will trigger
469-
# self._get_lease() as soon as the children change again.
470-
self.client.get_children(self.path, self._get_lease)
471472
return False
473+
finally:
474+
lock.release()
472475

473476
def _watch_lease_change(self, event):
474477
self.wake_event.set()

0 commit comments

Comments
 (0)