Skip to content

Commit

Permalink
Set redis expiration for lock to ensure removal.
Browse files Browse the repository at this point in the history
  • Loading branch information
bbangert committed Jan 10, 2012
1 parent 651c911 commit 40453cd
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions retools/lock.py
Expand Up @@ -55,6 +55,7 @@ def __enter__(self):
if redis.setnx(self.key, expires):
# We gained the lock; enter critical section
self.start_time = time.time()
redis.expire(self.key, expires)
return

current_value = redis.get(self.key)
Expand All @@ -63,6 +64,7 @@ def __enter__(self):
if current_value and float(current_value) < time.time() and \
redis.getset(self.key, expires) == current_value:
self.start_time = time.time()
redis.expire(self.key, expires)
return

timeout -= 1
Expand Down

0 comments on commit 40453cd

Please sign in to comment.