diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2018-11-14 17:53:01 -0800 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2018-11-14 17:53:01 -0800 |
commit | c99d2b98ff928a0709ee0453b60002e3e1254674 (patch) | |
tree | e63ce2289fab5d6d0ef4a8864b56184f41be9a2e /redis/lock.py | |
parent | 255f01036f6a8d10b4369eca9e491d13d3c3788a (diff) | |
download | redis-py-v3-breaking-changes.tar.gz |
raise a LockError when the context manager fails to acquire a lockv3-breaking-changes
Fixes #621
Fixes #927
Diffstat (limited to 'redis/lock.py')
-rw-r--r-- | redis/lock.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/redis/lock.py b/redis/lock.py index fb73ce2..05d4153 100644 --- a/redis/lock.py +++ b/redis/lock.py @@ -125,8 +125,9 @@ class Lock(object): def __enter__(self): # force blocking, as otherwise the user would have to check whether # the lock was actually acquired or not. - self.acquire(blocking=True) - return self + if self.acquire(blocking=True): + return self + raise LockError("Unable to acquire lock within the time specified") def __exit__(self, exc_type, exc_value, traceback): self.release() |