Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
The event loop runs one coroutine at a time and switches when a coroutine awaits something not ready; a blocking call never yields control, so the entire loop and every other task freeze until it finishes.
async def functions return coroutine objects that the loop schedules as tasks. When a task awaits I/O, it suspends, and the loop runs other ready tasks, resuming the first when its I/O completes. This cooperative model requires each task to yield regularly. Calling time.sleep, a synchronous HTTP client or a heavy CPU loop inside a coroutine blocks the thread, so the server cannot answer any request in the meantime. Use async libraries, await asyncio.sleep, or move blocking work to a thread with asyncio.to_thread or to a process pool. To run tasks concurrently, create them with asyncio.gather or a TaskGroup instead of awaiting them one by one.