Merge pull request #1908 from leonelcamara/make_sure_to_unlock_redis

Release the lock even if function call fails
This commit is contained in:
mdipierro
2018-04-29 19:50:33 -05:00
committed by GitHub
+2
View File
@@ -159,12 +159,14 @@ 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)
try:
# someone may have computed it # someone may have computed it
obj = self.r_server.get(newKey) obj = self.r_server.get(newKey)
if obj is None: if obj is None:
value = self.cache_it(newKey, f, time_expire) value = self.cache_it(newKey, f, time_expire)
else: else:
value = pickle.loads(obj) value = pickle.loads(obj)
finally:
release_lock(self, lock_key, al) release_lock(self, lock_key, al)
else: else:
# without distributed locking # without distributed locking