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).

Answer from Viktor Kerkez on Stack Overflow
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ threading.html
threading โ€” Thread-based parallelism โ€” Python 3.14.3 ...
This is one of the simplest mechanisms for communication between threads: one thread signals an event and other threads wait for it.
Discussions

Equivalent of Python threading.Event for sync Rust
A simple and useful synchronization primitive in Python is threading.Event. It's basically a boolean flag that can be written to and read from an arbitrary number of threads, but it is also possible to block and wait with a timeout until the flag is set. I am trying to find a similar concurrency ... More on users.rust-lang.org
๐ŸŒ users.rust-lang.org
2
0
June 29, 2024
multithreading - Python threading: will Event.set() really notify every waiting thread - Stack Overflow
Or could it happen that those two lines are executed so quickly after each other, that some threads might still be waiting? (i.e. Event.wait() polls the event's state, which might be already "cleared" again) Thanks for your answers! ... In the internals of Python, an event is implemented with ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python Threading Tutorial: Basic to Advanced (Multithreading, Pool Executors, Daemon, Lock, Events)
This video was pretty basic and did cover some of the topics in . However, some of your explanations were not quite correct. For example: Your explanation of what a thread was said that you needed them to share memory. This is not correct. Memory sharing is available to separate processes. Then you were saying that locks were needed to share memory. This is also not entirely true, and your example was what I would term naive: in that while it would work, it could cause bottlenecks for non trivial code. More on reddit.com
๐ŸŒ r/Python
10
192
November 4, 2024
Can someone ELI5 threading?

A program runs a bunch of instructions. For example, "add 2 and 5", and "print the words 'Hello world' to the console". Normally, these would happen one after the other. First, the program would perform the addition and then would print to the console.

We can use "threads" to do multiple things at once. Our program would create a separate thread that would do nothing but "add 2 and 5" and would then create another thread that would do nothing but "print the words 'Hello world' to the console". These threads can run at the same time, rather than in a predetermined order. The program would be adding and printing at the same time.

This comes with a few drawbacks. We have some data, lets say an integer with a value of 1. When we use this data in our first thread, we change the integers value to 2. In our second thread we are going to be printing that same integer. We run our program about 1000 times. Sometimes, our program prints 1 and sometimes it prints 2. This is because sometimes one thread is quicker at it's job than the other. If thread one is quicker than thread two, then we will see 2 printed out. If thread 2 is quicker than thread 1, then we will see 1 printed it.

Hopefully this is helpful. I added the bit about the drawbacks to give you a bit more knowledge than requested.

More on reddit.com
๐ŸŒ r/learnpython
13
27
October 22, 2013
๐ŸŒ
Medium
dailybytes.medium.com โ€บ mastering-pythons-threading-event-cc0926ef6a88
Mastering Pythonโ€™s threading.Event() | by Vivek | Medium
March 17, 2025 - threading.Event() is a built-in Python class that provides a simple way to synchronize threads.
๐ŸŒ
Python Tutorial
pythontutorial.net โ€บ home โ€บ python concurrency โ€บ python threading event
Python Threading Event
June 3, 2023 - In this tutorial, you'll learn how to use the Python threading Event object to communicate between threads.
๐ŸŒ
Dkharazi
dkharazi.github.io โ€บ notes โ€บ py โ€บ threading โ€บ event
threading.Event
This is because Condition is an abstracted Event + Lock ยท >>> from threading import Thread, Event >>> import time >>> start_signal = Event() >>> def turtle(): ... print('go turtle') ... time.sleep(5) ... print('signal rabbit') ... start_signal.set() ... time.sleep(10) ...
๐ŸŒ
Instructables
instructables.com โ€บ design โ€บ software
Starting and Stopping Python Threads With Events in Python Threading Module. : 4 Steps - Instructables
March 5, 2024 - Starting and Stopping Python Threads ... to start and stop threads using events. Threads are a way to execute multiple tasks concurrently within a single process Multithreading ......
๐ŸŒ
Medium
rahulsreedharan.medium.com โ€บ seamless-multithreading-with-python-events-a-complete-guide-a1c5a3457e26
Seamless Multithreading with Python Events: A Complete Guide | by RSDevX | Medium
March 7, 2024 - Seamless Multithreading with Python Events: A Complete Guide In Python, events typically refer to synchronization primitives provided by the threading module for coordinating communication between โ€ฆ
Find elsewhere
๐ŸŒ
Super Fast Python
superfastpython.com โ€บ home โ€บ tutorials โ€บ threading event object in python
Threading Event Object In Python - Super Fast Python
September 11, 2022 - You can use an Event Object in Python via the threading.Event class. In this tutorial you will discover how to use an event object in Python. Letโ€™s get started. Need for an Event Object A thread is a thread of execution in a computer program. Every Python program has at least one thread of execution [โ€ฆ]
๐ŸŒ
Bogotobogo
bogotobogo.com โ€บ python โ€บ Multithread โ€บ python_multithreading_Event_Objects_between_Threads.php
Python Multithreading Tutorial: Event Objects between Threads - 2020
We're using multiple threads to spin separate operations off to run concurrently, however, there are times when it is important to be able to synchronize two or more threads' operations. Using Event objects is the simple way to communicate between threads.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ implement-inter-thread-communication-with-event-method-in-python
Implement Inter Thread Communication with Event( ) Method in Python - GeeksforGeeks
November 26, 2022 - In simple words sometimes one thread may be required to communicate to another thread depending on the requirements. This is considered as Inter Thread Communication. Event() Method: Here we talk about the Event() method, the Event object is considered or recommended as the simplest communication process or system between any threads.
๐ŸŒ
StrataScratch
stratascratch.com โ€บ blog โ€บ python-threading-like-a-pro
Python Threading Like a Pro - StrataScratch
September 6, 2023 - Event allows one thread to signal one or more other threads that a particular event has occurred. Condition: This is a more complex synchronization tool that allows one thread to wait for a particular condition to be met while other threads ...
๐ŸŒ
Medium
medium.com โ€บ @surve.aasim โ€บ thread-synchronization-in-python-using-event-dbe1752eb5c7
Thread Synchronization in Python using threading.Event | by Aasim | Medium
August 17, 2023 - The integration of threading.Event empowers the primary thread to pause until a specific circumstance is met (here, the task fulfillment of the subordinate thread) before proceeding with its own execution.
Top answer
1 of 3
17

In the internals of Python, an event is implemented with a Condition() object.

When calling the event.set() method, the notify_all() of the condition is called (after getting the lock to be sure to be not interrupted), then all the threads receive the notification (the lock is released only when all the threads are notified), so you can be sure that all the threads will effectively be notified.

Now, clearing the event just after the notification is not a problem.... until you do not want to check the event value in the waiting threads with an event.is_set(), but you only need this kind of check if you were waiting with a timeout.

Examples :

pseudocode that works :

#in main thread
event = Event()
thread1(event)
thread2(event)
...
event.set()
event.clear()

#in thread code
...
event.wait()
#do the stuff

pseudocode that may not work :

#in main thread
event = Event()
thread1(event)
thread2(event)
...
event.set()
event.clear()

#in thread code
...
while not event.is_set():
   event.wait(timeout_value)
#do the stuff

Edited : in python >= 2.7 you can still wait for an event with a timeout and be sure of the state of the event :

event_state = event.wait(timeout)
while not event_state:
    event_state = event.wait(timeout)
2 of 3
16

It's easy enough to verify that things work as expected (Note: this is Python 2 code, which will need adapting for Python 3):

import threading

e = threading.Event()
threads = []

def runner():
    tname = threading.current_thread().name
    print 'Thread waiting for event: %s' % tname
    e.wait()
    print 'Thread got event: %s' % tname

for t in range(100):
    t = threading.Thread(target=runner)
    threads.append(t)
    t.start()

raw_input('Press enter to set and clear the event:')
e.set()
e.clear()
for t in threads:
    t.join()
print 'All done.'

If you run the above script and it terminates, all should be well :-) Notice that a hundred threads are waiting for the event to be set; it's set and cleared straight away; all threads should see this and should terminate (though not in any definite order, and the "All done" can be printed anywhere after the "Press enter" prompt, not just at the very end.

๐ŸŒ
Real Python
realpython.com โ€บ intro-to-python-threading
An Intro to Threading in Python โ€“ Real Python
August 5, 2024 - Technically, this example wonโ€™t have a race condition because x is local to inc(). It does illustrate how a thread can be interrupted during a single Python operation, however. The same LOAD, MODIFY, STORE set of operations also happens on global and shared values. You can explore with the dis module and prove that yourself. Itโ€™s rare to get a race condition like this to occur, but remember that an infrequent event taken over millions of iterations becomes likely to happen.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ threading
Python | Threading | Codecademy
April 21, 2025 - The threading module allows multiple threads of execution to take place in a Python program.
๐ŸŒ
Reddit
reddit.com โ€บ r/python โ€บ python threading tutorial: basic to advanced (multithreading, pool executors, daemon, lock, events)
r/Python on Reddit: Python Threading Tutorial: Basic to Advanced (Multithreading, Pool Executors, Daemon, Lock, Events)
November 4, 2024 -

Are you trying to make your code run faster? In this video, we will be taking a deep dive into python threads from basic to advanced concepts so that you can take advantage of parallelism and concurrency to speed up your program.

  • Python Thread without join()

  • Python Thread with join()

  • Python Thread with Input Arguments

  • Python Multithreading

  • Python Daemon Threads

  • Python Thread with Synchronization using Locks

  • Python Thread Queue Communication between Threads

  • Python Thread Pool Executor

  • Python Thread Events

  • Speed Comparison I/O Task

  • Speed Comparison CPU Task (Multithreading vs Multiprocessing)

https://youtu.be/Rm9Pic2rpAQ

๐ŸŒ
Studytonight
studytonight.com โ€บ python โ€บ python-threading-event-object
Python Event Object | Studytonight
This class is used for inter thread communication by generating events. The Event class object provides a simple mechanism which is used for communication between threads where one thread signals an event while the other threads wait for it.