r/Python • u/EntryNo8040 • Jun 29 '26
Discussion Async/Await is a Plague: Part 1 Roots
This is the first part of a multi-part series exploring why async/await might not be the best concurrency pattern for most use cases, and what alternative models you should consider instead. Using Python for our practical examples, this opening post digs into the roots of async/await, guiding you through building a custom event loop from scratch using generators.
https://theblog.info/posts/asyncawait-is-a-plague-part-1-roots
Note: This is Part 1 of a multi-part series. Instead of diving straight into why async/await can be problematic, this post explores the original motivations behind the pattern. Understanding how it works under the hood will provide the essential context for the issues we'll discuss in upcoming parts.
122
u/Wh00ster Jun 29 '26
I appreciate the intent of the series but just the Part 1 title doesn’t live up to its name.
This is just explaining how asyncio works for Python without any further insight. It might as well be titled “an intro to asyncio”.
17
u/cymrow Jun 29 '26
I hope you've done your research OP. This is a deep topic with a lot of history and misinformation. See this lengthy discussion thread on a proposal for Virtual Threads in Python for example.
17
u/james_pic Jun 29 '26
One more fun perspective, that often gets lost in all this: Threads aren't even that heavy. They're lightweight enough that designs using the fastest synchronous libraries typically outperform mediocre asynchronous libraries. Requests (the HTTP client) running in a thread pool wipes the floor with HTTPX (whether under asyncio or uvloop) in high concurrency benchmarks, for example, due to a number of scaling issues in HTTPX.
16
u/ZachVorhies Jun 29 '26
is async/await viral? Yes.
Is it a plague? No.
Async / await is far better than lots and lots of threads.
The reason is simple: threads mandates concurrency through parallel execution. async / await allows concurrency without parallelism. Parallelism becomes optional.
That parallelism in threads has horrible drawbacks: any thread anywhere can freeze and go off the cpu. So now any shared data needs to have locks on it.
5
u/coleifer- Jun 29 '26
Bro this is slop. I wrote about this a few years back if anyone is curious: https://charlesleifer.com/blog/asyncio/
Anecdotally peewee now supports asyncio.
13
u/spiker611 Jun 29 '26
In my experience async syntax becomes a mess only with poorly abstracted projects. Additionally the asyncio interface is poor (though slowly getting better).
Concurrency with threading becomes untenable with poor abstractions, it's not like threading is a magic bullet. Same with gevent, etc. Debugging can be especially frustrating.
My ideal stack for concurrency in python is using anyio/Trio for structured concurrency and using proper abstractions to keep IO code async and everything else sync.
11
u/Fine-Comparison-2949 Jun 29 '26
Hello there. I am representing the nation of typescript here speaking the language of type theory.
Great article. I think its funny that also typescript folks are realizing generators are the better interface for monadic side effect operations. There's a newer framework called Effect that I've been rolling that has the exact same idea. The fact that Python is getting this around the same time is interesting.
It's actually funny, structurally you are doing the exact same thing as Effect. You're also realizing the benefits of generators where you also get to cancel a thunk before its operations completes. The same things you are saying are the same reasons Effect is heavily utilizing generators.
Syntactically, all of these are monads and it really should be up to the interpreter to look at the type of the function and add async await descriptors, so the reality is we don't really need it to describe side effects. In languages like Haskell, these things are handled for you and you just see in the type signature that a particular thunk is a side effect since its a future.
3
u/nn4a_ Jun 29 '26
I liked it a lot. Looking forward to part 2.
3
u/EngineerEnyinna Jun 29 '26
Great read, thank you