Python condition variable timeout
condition-variable, multithreading, python
Solution
You are not supposed to care; the typical case is that your waiting thread checks some shared state until that state matches some condition.
The documentation example is thus:
cv.acquire()
while not an_item_is_available():
cv.wait()
get_an_available_item()
cv.release()
and the documentation also states:
[…] threads that are interested in a particular change of state call wait() repeatedly until they see the desired state
If you do have a pressing need to distinguish between a timeout and a signal, you'll need to use `Event` objects instead; the `.wait(timeout)` call on an `Event` object returns `None` if the flag wasn't set (which only happens when the timeout was reached).
Problem
I have thread1 which is waiting on a condition from thread2. But it could be that thread2 is never signalling the condition variable. So I have added a timeout to the `wait` call in thread 1, like this: ``` cv.acquire() cv.wait(1.0) cv.release() ``` How can I know if the condition variable was signaled or a timeout occurred? `wait` does not seem to return any value. The python documentation on Condition Objects gives no clues about this.