async and await
async and await: async and await in Plain Words, Async Routes: When They Help, and When They Don't.
Updated
- async and await in Plain Words (Journeyman): Most of a back end's time goes on waiting, so an async def function can pause at each await and let other work run, asyncio.gather waits for two things at once instead of one after the other, and time.sleep inside async def holds up everything else.
- Async Routes: When They Help, and When They Don't (Freelancer): An async def route that calls other services with httpx's AsyncClient can ask them all at once with asyncio.gather and give up after a timeout with a 503, while routes with blocking code such as sqlite3 stay plain def, because one blocking call inside async def holds up every request.