© Mohamed Mustapha Tahrioui 2019
M. M. Tahriouiasyncio Recipeshttps://doi.org/10.1007/978-1-4842-4401-2_3

3. Working with Coroutines and Async/Await

Mohamed Mustapha Tahrioui1 
(1)
Darmstadt, Hessen, Germany
 

A coroutine is a work unit for an event loop/scheduler and can be understood as a suspendible function. The “co” in coroutine does not stem from the word concurrent, but rather from the word cooperative .

The coroutine “cooperates” with the event loop that schedules the coroutine. If the coroutine is “logically blocked,” meaning it waits on some sort of I/O, the coroutine can yield control back to the event loop. The loop can then decide how to use the freed resources (CPU time) to dispatch other “waiting and ready” coroutines. The loop can then ...

Get asyncio Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.