The event-loop mental model
P33.event-loop.01 · Audience: guest, it-ml, language-pro · Prerequisites: Context managers & yield as a doorway
async/await feels like new magic, but it is the generator machinery you
already know (P29), pointed at concurrency. Before touching asyncio, you'll
build an event loop by hand — a scheduler that takes turns stepping suspended
functions — so the real one holds no mysteries.
ⓘ Concept: yield is a pause button
yield, hands control back, and resumes from exactly that point next time you step it. That is the one primitive an event loop needs: a unit of work that can voluntarily pause and be resumed later.Why it matters — Once you see that a generator is a function you can stop and restart, a coroutine is no longer exotic — it is the same object with nicer syntax.
Ask the mentor about this module
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
🎓 Practice ladder
2 graded rungs · ~22 minBuild the loop yourself over generators, then put the mental model into words.
Rung 1 — build an event loop from generators
Loading exercise…
Rung 2 — explain the event loop (interview)
Loading exercise…
You built the scheduler; the next module hands you the real one — asyncio —
where gather, timeouts and TaskGroups run genuine coroutines. Those rungs run
on the kernel, because real asyncio needs a real Python event loop.
Where next?
Later in The Event Loop
Go up a level