Created
April 27, 2016 15:24
-
-
Save jesg/d34167c49a2db93bb172947cafa439ec to your computer and use it in GitHub Desktop.
lock with timeout for python 2.7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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