asyncio
- This library takes advantage of two new Python reserved keywords:
async
andawait
await
can be thought of as an asynchronous version ofyield from
, and has to be inside a coroutine- When the program reaches the
await
statement, the control is handed off to the event loop, which finds the next thing to run- this behaves very similarly to a
yield
in generators
- this behaves very similarly to a
Useful Functions
asyncio.run
asyncio.gather
asyncio.wait
asyncio.Queue
Useful Helper Libraries
aiohttp
aiofiles
aiomultiprocessing
concurrent.futures
Two patterns I’ve seen so far:
- Quickly toggle between multiprocessing and multithreading
- Schedule buffered and concurrent pipelines
Note: This is also achievable using asyncio.wait