asyncio is all the rage these days in Python because we can write high performance io code in a single thread. While there are a lot of tutorials on a

Demystifying Asynchronous Programming in Python

submited by
Style Pass
2021-06-18 15:00:08

asyncio is all the rage these days in Python because we can write high performance io code in a single thread. While there are a lot of tutorials on asyncio library itself, there is little explanation on how it works internally. Although asyncio library uses the async/await syntax, the syntax itself is independent of the library.

It’s commonly said that async/await is just syntactic sugar for coroutines, but I never really understood what this means. So, I will try to dig deep into coroutines and write my own simple network io program with coroutines. With this, idea behind the syntax and asyncio library should become apparent.

Python Enhancement Proposal (PEP) 492 introduced async/await syntax into the language. Here’s the relevant passage from the abstract:

It is proposed to make coroutines a proper standalone concept in Python, and introduce new supporting syntax. The ultimate goal is to help establish a common, easily approachable, mental model of asynchronous programming in Python and make it as close to synchronous programming as possible.

Leave a Comment