Skip to content

Commit

Permalink
Rate Watcher: Improve locking behavior in corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
desbma committed Nov 12, 2016
1 parent 970747a commit ed57e3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,6 +1,6 @@
appdirs>=1.4.0
cssselect>=0.9.1
lockfile>=0.12.2
lockfile==0.12.2
lxml>=3.3.3,<4.0.0
mutagen>=1.31
pillow>=2.7.0
Expand Down
10 changes: 7 additions & 3 deletions sacad/rate_watcher.py
Expand Up @@ -11,7 +11,8 @@
import lockfile


MIN_WAIT_TIME_S = 0.05
MIN_WAIT_TIME_S = 0.01
SUSPICIOUS_LOCK_AGE_S = 120


class WaitNeeded(Exception):
Expand Down Expand Up @@ -81,7 +82,10 @@ def _getLock(self):
try:
plock.acquire(timeout=0)
except (lockfile.LockTimeout, lockfile.AlreadyLocked):
# TODO detect and break locks of dead processes
# detect and break locks of dead processes
lock_age = time.time() - os.path.getmtime(plock.lock_file)
if lock_age > SUSPICIOUS_LOCK_AGE_S:
plock.break_lock()
tlock.release()
except:
tlock.release()
Expand All @@ -91,5 +95,5 @@ def _getLock(self):
return False

def _releaseLock(self):
__class__.thread_locks[self.domain].release()
lockfile.FileLock(os.path.join(self.lock_dir, self.domain)).release()
__class__.thread_locks[self.domain].release()

0 comments on commit ed57e3a

Please sign in to comment.