Skip to main content

← All terms · Async & concurrency

asyncio.wait_for

Cap any awaitable with a timeout: `await asyncio.wait_for(coro, timeout=5)`. Raises `TimeoutError` on expiry and cancels the inner task. Essential for any external call.

Learn this interactively:

Open lesson sr-22

Related — Async & concurrency

async defDeclares a coroutine. Can be awaited; runs cooperatively on an event loop.awaitPauses a coroutine until another coroutine/Future finishes. Only legal inside `aEvent loopScheduler that drives async code — runs ready coroutines, parks blocked ones. `aGILGlobal Interpreter Lock — CPython's mutex that lets only one thread run Python basyncio.gatherRun multiple coroutines concurrently and wait for all of them. The bread-and-butasyncio.TaskGroupStructured concurrency primitive (Python 3.11+). `async with TaskGroup()` ensure