LOG 010 · TECHNICAL · 2022-08-29
Using Asyncio in Python - the book that finally made the event loop click
1 min read
I picked this up while implementing FastAPI’s async mode and realising I didn’t properly understand how it worked underneath. I finally feel confident with the event loop and asyncio after reading this short book, and that alone earns it 4/5 from me.
My best takeaway was the explanation of why asyncio feels so hard in the first place: the API has a readability problem. The problem is that the API has to cater to framework developers as well as end user developers. The needs of a framework developer are much more complex and specific, but the flat hierarchy of the asyncio docs obscures this. So the regular developer who just wants to run things asynchronously gets easily confused when reading the docs, as I did. Once that clicked, the event loop itself finally made sense, and realising the confusion was the docs’ fault and not mine was half the battle.
Beyond that diagnosis, the book walks through the history of asyncio and its common real life use cases, and gives you enough event loop theory to make the whole thing easier to grasp. It changed how I write Python day to day. I’m much more confident with async now and reach for it far more, using async libraries like httpx instead of requests. That confidence has held up ever since.
Why not 5/5? The prose could have been better and more readable.
Who should read it: anyone who isn’t yet comfortable with async. If you already write async Python comfortably, you can skip it.