LESSON 1.11 · 6 STAGES · 2 CONTROLS · 3 CHECKSPRO · PREVIEW
The asyncio event loop
Watch one event loop run two coroutines on one thread, switching at each await.
Needs1.10 Multiprocessing
Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 2 controls and 3 checks, in this lesson and every other.
Go Pro · $8.25/moEXPLAINER · 1.11 · EVENT LOOP BAYT = 0 MS · TICK 0 · 1 READY · 0 TIMERS
01
Stage 1 of 6 · Make a coroutine
main() makes a coroutine and runs no line. asyncio.run wraps it in a task on a new event loop.
Explain it simply
Calling main doesn't run its code. It makes a coroutine, an object that holds a function call that hasn't started. asyncio.run then makes the event loop, the panel at the top, and wraps main in a task. The task's first step waits in the ready queue, like a ticket in a line.
The coroutine main has not started: CORO_CREATED at line 15. Task main holds it. The ready queue holds main's first step. The clock shows 0 ms.
frame, event loopcoroutine, task, Python workawait, timerI/O waitrunning code, outputblocked or late
Toy: I/O 1 and I/O 2 of the 1.C1 toy · 51 ms and 43 ms waits · 5 ms of Python each side · CPython 3.12
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
A call to an async function makes a coroutine and runs nothing.
PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
- 5 more stages and 2 live controls
- 2 mix-up cards and 3 predict-then-reveal checks
- Watch it as a narrated video, in three voices
- Every Pro lesson and capstone · 656 in total
$99 a year, or $15 a month. Cancel any time.