diff options
author | Joshua Harlow <josh.harlow@plus.ai> | 2018-12-03 11:04:34 -0800 |
---|---|---|
committer | Joshua Harlow <josh.harlow@plus.ai> | 2018-12-03 13:27:24 -0800 |
commit | 26b3828678560fedb8c9cc04362e7c20b01d2f77 (patch) | |
tree | 552498c50deef6a02d2f5e19468ab02b38bb8d0a /redis/lock.py | |
parent | 5784bc90717d7632eabd1e0d642a5364cea4f0c8 (diff) | |
download | redis-py-26b3828678560fedb8c9cc04362e7c20b01d2f77.tar.gz |
Extend lock error for not owned special case
Using the locking routines, it is useful to be able to
distingush a generic lock error from a one that is related
to the lock not being owned anymore (without doing string
checks); this allows say a lock extension thread to attempt
to re-acquire the lock in this case (vs just dying).
Diffstat (limited to 'redis/lock.py')
-rw-r--r-- | redis/lock.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/redis/lock.py b/redis/lock.py index c6fd01d..38ab0bf 100644 --- a/redis/lock.py +++ b/redis/lock.py @@ -1,7 +1,7 @@ import threading import time as mod_time import uuid -from redis.exceptions import LockError +from redis.exceptions import LockError, LockErrorNotOwned from redis.utils import dummy @@ -190,7 +190,8 @@ class Lock(object): if not bool(self.lua_release(keys=[self.name], args=[expected_token], client=self.redis)): - raise LockError("Cannot release a lock that's no longer owned") + raise LockErrorNotOwned("Cannot release a lock" + " that's no longer owned") def extend(self, additional_time): """ @@ -210,5 +211,6 @@ class Lock(object): if not bool(self.lua_extend(keys=[self.name], args=[self.local.token, additional_time], client=self.redis)): - raise LockError("Cannot extend a lock that's no longer owned") + raise LockErrorNotOwned("Cannot extend a lock that's" + " no longer owned") return True |