Tasks, gather & timeouts
P33.event-loop.02 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: The event-loop mental model
Where next?
This module unlocks
Go up a level
P33.event-loop.02 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: The event-loop mental model
This module unlocks
Go up a level
Time for the real event loop. asyncio.gather runs many coroutines at once and
collects their results; asyncio.wait_for bounds one so a hang becomes a clean
timeout. Both rungs run on the kernel — real asyncio can't grade in the
browser, so these execute in real CPython.
await asyncio.gather(coro1, coro2, ...) schedules every coroutine on the loop, lets them overlap their waiting, and returns a list of results in the order you passed them — not the order they finished. One line, real concurrency.Why it matters — gather is the workhorse of async I/O: it turns a list of independent awaits into one concurrent batch, without you touching the loop.
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.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
Fan out real coroutines with gather, then bound one with
wait_for — both graded on the kernel.
Loading exercise…
Loading exercise…
gather runs tasks — but if one fails, the rest leak on. The next track fixes
that with structured concurrency: tasks that cannot outlive their block.
Loading your notes...