I have a main python script which starts a thread running in the background.
poll = threading.Thread(target=poll_files, args=myargs)
I want my main script to wait until something specific happens in my poll
thread. I want to use an Event object. So in my main script, I do:
trigger = threading.Event()
and when I want to wait:
trigger.wait()
My question is, inside my poll
thread, how do I set the Event to True? I know I do:
trigger.set()
but do I need to also have trigger = threading.Event()
inside my poll
thread?
Pass the Event
object to the thread target function so that they are shared between main thread and the pool
thread:
def poll_files(....., trigger):
....
trigger.set()
# main thread
trigger = threading.Event()
poll = threading.Thread(target=poll_files, args=myargs + (trigger,))
...
trigger.wait()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With