Python Threading with Event object

Because someone else will set it.

You generally start a thread in one part of your application and continue to do whatever you do:

thread = TimerClass()
thread.start()
# Do your stuff

The thread does it’s stuff, while you do your stuff. If you want to terminate the thread you just call:

thread.event.set()

And the thread will stop.

So the answer is: event, in this case, is not used for controlling the thread from inside the thread object itself. It is used for controlling the thread from outside (from the object which holds the reference to the thread).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)