You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
print("I already acquired this in another process.")
else:
print("The lock is held on another machine.")
has an unreachable code path and implies an impossible use case.
The example implies that a lock with an explicit ID can return False from .acquire(blocking=False) AND have the lock owned by self per lock.get_owner_id() == host_id check, which is actually just the same check as _held property, which will instead cause .acquire(blocking=False) to raise an exception.
Ideally I would like to be able to give locks in multiple processes the same ID and be able to call .acquire(blocking=False) and have it return False instead of raising AlreadyAcquired. I thought that was possible from reading the examples.
Then when I got AlreadyAcquired I had to change my code to try .acquire(): except AlreadyAcquired instead of if .acquire(), which is fine, except that the example further confused me by implying I might need to support both False or AlreadyAcquired in the event that I am unable to acquire the lock.
The text was updated successfully, but these errors were encountered:
This example
python-redis-lock/README.rst
Lines 103 to 114 in 1497012
The example implies that a lock with an explicit ID can return
False
from.acquire(blocking=False)
AND have the lock owned by self perlock.get_owner_id() == host_id
check, which is actually just the same check as_held
property, which will instead cause.acquire(blocking=False)
to raise an exception.Ideally I would like to be able to give locks in multiple processes the same ID and be able to call
.acquire(blocking=False)
and have it returnFalse
instead of raisingAlreadyAcquired
. I thought that was possible from reading the examples.Then when I got
AlreadyAcquired
I had to change my code totry .acquire(): except AlreadyAcquired
instead ofif .acquire()
, which is fine, except that the example further confused me by implying I might need to support bothFalse
orAlreadyAcquired
in the event that I am unable to acquire the lock.The text was updated successfully, but these errors were encountered: