Skip to content

Commit

Permalink
fix(recipe): fix deprecation warning from threading.Event
Browse files Browse the repository at this point in the history
reasoning:
- `is_set` is supported since Python2.6 (https://docs.python.org/2.7/library/threading.html)
- Starting from Python3.5 docs the `isSet` spelling is not even mentioned anymore (https://docs.python.org/3.5/library/threading.html)
- Python3.10 will give a deprecation warning when the `isSet` spelling is used (https://docs.python.org/3.10/library/threading.html)
  • Loading branch information
stefreak committed Dec 2, 2021
1 parent 1ea097d commit 569c89c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions kazoo/recipe/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def _inner_acquire(self, blocking, timeout, ephemeral=True):
pass # predecessor has already been deleted
else:
self.wake_event.wait(timeout)
if not self.wake_event.isSet():
if not self.wake_event.is_set():
raise LockTimeout(
"Failed to acquire lock on %s after %s seconds"
% (self.path, timeout)
Expand Down Expand Up @@ -638,7 +638,7 @@ def _inner_acquire(self, blocking, timeout=None):
# If blocking, wait until self._watch_lease_change() is
# called before returning
self.wake_event.wait(w.leftover())
if not self.wake_event.isSet():
if not self.wake_event.is_set():
raise LockTimeout(
"Failed to acquire semaphore on %s"
" after %s seconds" % (self.path, timeout)
Expand Down
2 changes: 1 addition & 1 deletion kazoo/recipe/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def check_for_updates(event):
if event is not None and event.type != EventType.CHILD:
return
with lock:
if canceled or flag.isSet():
if canceled or flag.is_set():
return
values = self.client.retry(
self.client.get_children,
Expand Down
4 changes: 2 additions & 2 deletions kazoo/testing/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ def watch_loss(state):
self.client._call(break_event, None)

lost.wait(5)
if not lost.isSet():
if not lost.is_set():
raise Exception("Failed to get notified of broken connection.")

safe.wait(15)
if not safe.isSet():
if not safe.is_set():
raise Exception("Failed to see client reconnect.")

self.client.retry(self.client.get_async, '/')
Expand Down
8 changes: 4 additions & 4 deletions kazoo/tests/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def _thread(lock, event, timeout):
with lock:
started.set()
event.wait(timeout)
if not event.isSet():
if not event.is_set():
# Eventually fail to avoid hanging the tests
self.fail("lock2 never timed out")

Expand All @@ -409,7 +409,7 @@ def _thread(lock, event, timeout):
client2 = self._get_client()
client2.start()
started.wait(5)
assert started.isSet() is True
assert started.is_set() is True
lock2 = client2.Lock(self.lockpath, "two")
try:
lock2.acquire(timeout=timeout)
Expand Down Expand Up @@ -712,7 +712,7 @@ def _thread(sem, event, timeout):
with sem:
started.set()
event.wait(timeout)
if not event.isSet():
if not event.is_set():
# Eventually fail to avoid hanging the tests
self.fail("sem2 never timed out")

Expand All @@ -724,7 +724,7 @@ def _thread(sem, event, timeout):
client2 = self._get_client()
client2.start()
started.wait(5)
assert started.isSet() is True
assert started.is_set() is True
sem2 = client2.Semaphore(self.lockpath, "two")
try:
sem2.acquire(timeout=timeout)
Expand Down

0 comments on commit 569c89c

Please sign in to comment.