Loading topic
async def and await code and know what a generator is. You don't need to write coroutines fluently yet. The goal is a working model of what the event loop does between your await points, so that ordering, stalls, and "why did this run now?" questions hav6 min readasync def functions and await them, as covered in the previous chapter. It also assumes you know what a Python context manager is and how try/finally works. Here you learn how a normal, synchronous Python program hands control to the event loop, what happen5 min readasync def and await, and start one with asyncio.run. It also assumes you know that the event loop runs one piece of code at a time on a single thread.5 min readasync def and await, start a program with asyncio.run, and wrap a coroutine in a task with asyncio.create_task. It also assumes you know how try/except behaves. asyncio.gather is the shortest way to run several awaitables at once and get5 min readasyncio.create_task, and use asyncio.gather. You should also know try/except and context managers. TaskGroup needs Python 3.11 or later, and the except* syntax shown below does too.5 min readasyncio.run, and create tasks. It also assumes you know try/except and that gather and TaskGroup run work concurrently. Python 3.11 or later is needed for TaskGroup and except*.5 min readasyncio.create_task, await them, and use try/finally. Here you will learn what task.cancel() does, how to write coroutines that clean up when cancelled, and which mistakes make cancellation silently fail.5 min readtask.cancel() raises CancelledError inside the task at its current await. The examples use Python 3.11 or later.5 min readasyncio.create_task, and collect results with asyncio.gather. It also assumes you know what a context manager is. Here you will use Lock, Event, and Semaphore to control how tasks share resources, signal each other, and cap ho5 min readasyncio.run, create tasks, and use TaskGroup (Python 3.11+). It also assumes you know what cancellation does to a task. Here you will connect tasks with asyncio.Queue, so that producers and consumers run at their own pace without s5 min readasyncio.run, and run them concurrently with create_task and gather. It also assumes you know the difference between I/O-bound and CPU-bound work. Here you will learn how to run code that cannot await without freezing every other 5 min readwith statements and context managers, and the basics of coroutines and await from earlier chapters. Here you will see how the three protocols you already know get asynchronous versions. These are async for, async with, and `asy4 min readasyncio.run, run them together with tasks or gather, and use asyncio.timeout. You should also know basic TCP terms: host, port, connection, and byte stream.5 min readgather and TaskGroup. It also assumes you know how cancellation works, and that you run Python 3.11 or later. Most asyncio bugs come from a small set of mistakes: a missing await, a blocked loop, a lost task, or a swallowed e5 min read