event loop
In Python, the event loop is the scheduler that runs asynchronous tasks and callbacks one at a time on a single thread. Every asyncio program runs on one. The loop tracks a queue of ready callbacks alongside a set of pending I/O operations and works through them as they come due.
Each time a coroutine awaits something slow, it hands control back to the loop, which picks up the next piece of work that’s ready. That handoff is what gives you concurrency without threads. The loop never interrupts running code, so a coroutine holds the processor until it awaits.
A blocking call such as time.sleep() stalls every other task on the loop, because nothing yields control while it runs. Awaiting asyncio.sleep() instead suspends only the calling coroutine and leaves the loop free.
You rarely touch the loop directly. asyncio.run() creates one, runs your main coroutine on it, then closes it. Inside async code, asyncio.get_running_loop() returns the loop that’s currently in charge, and each thread runs at most one loop at a time.
Example
Say you’re loading three pages that each spend a second waiting on the network, and you want that second to overlap rather than stack up:
>>> import asyncio
>>> import time
>>> async def load(page):
... await asyncio.sleep(1)
... return page
...
>>> async def main():
... started = time.perf_counter()
... pages = await asyncio.gather(
... load("home"), load("docs"), load("blog")
... )
... print(pages, f"{time.perf_counter() - started:.1f}s")
...
>>> asyncio.run(main())
['home', 'docs', 'blog'] 1.0s
asyncio.gather() hands all three load() coroutines to the loop together. Each one awaits asyncio.sleep(), which suspends that coroutine and returns control to the event loop. The loop starts the other two while the first one waits, so three one-second delays finish in about one second rather than three.
Step through that same program below to watch where each task sits from one turn of the loop to the next, then flip the sleep call to time.sleep() and see the ready queue freeze:
Related Resources
Tutorial
Python's asyncio: A Hands-On Walkthrough
Explore how Python asyncio works and when to use it. Follow hands-on examples to build efficient programs with coroutines and awaitable tasks.
For additional information on related topics, take a look at the following resources:
- Hands-On Python 3 Concurrency With the asyncio Module (Course)
- Speed Up Your Python Program With Concurrency (Tutorial)
- Speed Up Python With Concurrency (Course)
- Python 3.14 Release Candidate Lands: Faster Code, Smarter Concurrency (Tutorial)
- Python's asyncio: A Hands-On Walkthrough (Quiz)
- Python Concurrency (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Martin Breuss • Updated Sept. 28, 2026