Release the lock even if function call fails

This commit is contained in:
Leonel Câmara
2018-04-20 16:55:05 +01:00
committed by GitHub
parent 94a9bfd05f
commit ea5ea6a307
+2
View File
@@ -160,11 +160,13 @@ class RedisClient(object):
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 # someone may have computed it
try:
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