Caffeinated Coder
Book an appointment
Lesson 25 · Idiomatic Python

asyncio

asyncio lets one Python thread juggle many slow waits. Follow brew.py, a ten-line program, through the event loop: a coroutine object that does nothing until something drives it, asyncio.run(), Tasks made with asyncio.TaskGroup, tasks parking at await while their timers run, and results kept on each Task. Two waits of 2 and 1 seconds finish together in about 2 seconds. Then meet the classic trap: awaiting coroutines one after another takes the full 3.

14 min10 steps5 questionsAdvanced
Fig 25 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.