Skip to content

Instantly share code, notes, and snippets.

@jesg
Created April 27, 2016 15:24
Show Gist options
  • Save jesg/d34167c49a2db93bb172947cafa439ec to your computer and use it in GitHub Desktop.
Save jesg/d34167c49a2db93bb172947cafa439ec to your computer and use it in GitHub Desktop.
lock with timeout for python 2.7
class LockWithTimeout(object):
def __init__(self):
self.queue = Queue(1)
self.queue.put(1, block=False)
def aquire(self, timeout=None):
try:
self.queue.get(block=True, timeout=timeout)
return True
except Empty:
return False
def release(self):
self.queue.put(1, block=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment