Merge pull request #1908 from leonelcamara/make_sure_to_unlock_redis
Release the lock even if function call fails
This commit is contained in:
@@ -159,13 +159,15 @@ class RedisClient(object):
|
|||||||
lock_key = '%s:__lock' % newKey
|
lock_key = '%s:__lock' % newKey
|
||||||
randomvalue = time.time()
|
randomvalue = time.time()
|
||||||
al = acquire_lock(self.r_server, lock_key, randomvalue)
|
al = acquire_lock(self.r_server, lock_key, randomvalue)
|
||||||
# someone may have computed it
|
try:
|
||||||
obj = self.r_server.get(newKey)
|
# someone may have computed it
|
||||||
if obj is None:
|
obj = self.r_server.get(newKey)
|
||||||
value = self.cache_it(newKey, f, time_expire)
|
if obj is None:
|
||||||
else:
|
value = self.cache_it(newKey, f, time_expire)
|
||||||
value = pickle.loads(obj)
|
else:
|
||||||
release_lock(self, lock_key, al)
|
value = pickle.loads(obj)
|
||||||
|
finally:
|
||||||
|
release_lock(self, lock_key, al)
|
||||||
else:
|
else:
|
||||||
# without distributed locking
|
# without distributed locking
|
||||||
value = self.cache_it(newKey, f, time_expire)
|
value = self.cache_it(newKey, f, time_expire)
|
||||||
|
|||||||
Reference in New Issue
Block a user