From ea5ea6a30759a2c825f23381540dc396cbc475b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Fri, 20 Apr 2018 16:55:05 +0100 Subject: [PATCH 1/2] Release the lock even if function call fails --- gluon/contrib/redis_cache.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gluon/contrib/redis_cache.py b/gluon/contrib/redis_cache.py index 110360eb..f8d43998 100644 --- a/gluon/contrib/redis_cache.py +++ b/gluon/contrib/redis_cache.py @@ -160,12 +160,14 @@ class RedisClient(object): randomvalue = time.time() al = acquire_lock(self.r_server, lock_key, randomvalue) # someone may have computed it - obj = self.r_server.get(newKey) - if obj is None: - value = self.cache_it(newKey, f, time_expire) - else: - value = pickle.loads(obj) - release_lock(self, lock_key, al) + try: + obj = self.r_server.get(newKey) + if obj is None: + value = self.cache_it(newKey, f, time_expire) + else: + value = pickle.loads(obj) + finally: + release_lock(self, lock_key, al) else: # without distributed locking value = self.cache_it(newKey, f, time_expire) From d6f426ed2968de5165a9926ed0ca59e5f2a042c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Fri, 20 Apr 2018 17:00:13 +0100 Subject: [PATCH 2/2] Update redis_cache.py fix comment position --- gluon/contrib/redis_cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gluon/contrib/redis_cache.py b/gluon/contrib/redis_cache.py index f8d43998..6241fbcf 100644 --- a/gluon/contrib/redis_cache.py +++ b/gluon/contrib/redis_cache.py @@ -159,8 +159,8 @@ class RedisClient(object): lock_key = '%s:__lock' % newKey randomvalue = time.time() al = acquire_lock(self.r_server, lock_key, randomvalue) - # someone may have computed it try: + # someone may have computed it obj = self.r_server.get(newKey) if obj is None: value = self.cache_it(newKey, f, time_expire)