How to implement a Lock with a timeout in Python 2.7
Is there a way to implement a lock in Python for multithreading purposes whose acquire method can have an arbitrary timeout? The only working solutions I found so far use polling, which I find inelegant and inefficient Doesn't preserve the bounded waiting / progress guarantee of the lock as a solution to the critical section problem Is there a better way to implement this? to elaborate on Steven's comment suggestion: import threading import time lock = threading.Lock() cond = threading.Condition(threading.Lock()) def waitLock(timeout): with cond: current_time = start_time = time.time() while