Make A Thread Wait For Either A Timer Or A Signal?
I am writing a Multithreaded Python application, in which each thread should wake up under the following circumstances: A signal from a main thread A Timer call started by itself
Solution 1:
Well, threading.Event, has a wait method, which takes a timeout. So you could do something as simple as
In main thread:
sleepEvent = threading.Event()
pass that to your other threads, and in them:
sleepEvent.wait(10) # wait for up to 10 seconds
Now your thread will either wait 10 seconds (like a timer) or will clear the wait if the main thread calls
sleepEvent.set()
Post a Comment for "Make A Thread Wait For Either A Timer Or A Signal?"