frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

What Python's asyncio primitives get wrong about shared state

https://www.inngest.com/blog/no-lost-updates-python-asyncio
20•goodoldneon•2h ago

Comments

TZubiri•1h ago
I'm sorry but how do you jump from 1. Polling to 2. Asyncio

There's so many solutions in the middle, I have this theory that most people that get into async don't really know what threading is. Maybe they have a world vision where before 2023 python just could not do more than one thing at once, that's what the GIL was right? But now after 3.12 Guido really pulled himself by the bootstraps and removed the GIL and implemented async and now python can do more than one thing at a time so they start learning about async to be able to do more than one thing at a time.

This is a huge disconnect between what python devs are actually building, a different api towards concurrency. And some junior devs that think they are learning bleeding edge stuff when they are actually learning fundamentals through a very contrived lens.

It 100% comes from ex-node devs, I will save the node criticism, but node has a very specific concurrency model, and node devs that try out python sometimes run to asyncio as a way to soften the learning curve of the new language. And that's how they get into this mess.

The python devs are working on these features because they have to work on something, and updates to foundational tech are supposed to have effects in decades, it's very rare that you need to use bleeding edge features. In 95% of the cases, you should be restricting yourself to using features from versions that are 5-10 years old, especially if you come from other languages! You should start old to new, not new to old.

Sorry, for the rant, or if I misjudged, making a broader claim based on multiple perspectives.

dbt00•1h ago
I think they were already in the async world and needed message passing -- the polling code was also in python async.
dbt00•1h ago
What about a more general message-passing mailbox approach? This works really well in the Erlang/gen_server/gen_fsm world. (and in plenty of other contexts, but Erlang's OTP is still some of the best, simplest incarnation of these things)
ydj•1h ago
I think it’s not so much that the asyncio primitives got wrong about shared state, as much as is what the authors got wrong about the usage of those primitives. They are classic concurrency primitives that’s been around for almost half a century. They work as designed, but require some care to use correctly.
jsanders9•2m ago
Agreed. This isn't an asyncio problem, it's just not how those primatices work.
pothamk•1h ago
One thing that trips people up with asyncio is that “single threaded” gets interpreted as “no concurrency hazards”.

But coroutines still interleave execution at every await point, so shared mutable state can become just as fragile as in multithreaded code — the scheduling boundary just moves from OS threads to cooperative yield points.

In practice that tends to push designs toward queues, actors, or message-passing patterns if you want to avoid subtle state corruption.

ipnon•17m ago
And in that case you begin to wonder why use Python at all? The language struggles to give developers the granularity needed to finely manage threads like C++, and it doesn't have the actor model first class like Erlang. I love Python, but I love Fortran and Lisp too. They've all served their purpose and it's time to move on, even though there is already incredible momentum behind it.
SkiFire13•9m ago
I don't fully agree with this. Yes, surely shared mutable state can suffer from similar issues, however the cooperative nature of coroutines makes this much easier to handle. OS threads are preemptive and actually run in parallel, so you have to be aware of CPU concurrency and always be ready for a context switch.
evil-olive•1h ago
the title seems unnecessarily clickbaity.

rather than "What Python's asyncio primitives get wrong" this seems more like "why we chose one asyncio primitive (queue) instead of others (event and condition)"

also, halfway through the post, the problem grows a new requirement:

> Instead of waking consumers and asking "is the current state what you want?", buffer every transition into a per-consumer queue. Each consumer drains its own queue and checks each transition individually. The consumer never misses a state.

if buffering every state change is a requirement, then...yeah, you're gonna need a buffer of some kind. the previous proposed solutions (polling, event, condition) would never have worked.

given the full requirements up-front, you can jump straight to "just use a queue" - with the downside that it would make for a less interesting blog post.

also, this is using queues without any size limit, which seems like a memory leak waiting to happen if events ever get enqueued more quickly than they can be consumed. notably, this could not happen with the simpler use cases that could be satisfied by events and conditions.

> A threading.Lock protects the value and queue list.

unless I'm missing something obvious, this seems like it should be an asyncio.Lock?

ggm•8m ago
yes. I felt something very similar. I do think there is value in pointing out the pitfalls naieve users (me!) can make assuming things which aren't true about ordering of events, states. Queues with lock regions are also really nice because they are (as I understand it) very cheap: so making a thread or other concurrency primitive which writes into a queue under lock, and gets out of the way, aligns nicely with having some mothership process which reads queues under lock in a deterministic way. Actual event order can vary. but you should be able to know you had an event putting you into state A, as well as the terminal event state B you jumped into without doing work needed for state A.
rpz•48m ago
Reminds me of https://geocar.sdf1.org/fast-servers.html

Large-Scale Agentic RL for CUDA Kernel Generation

https://cuda-agent.github.io/
1•gmays•4m ago•0 comments

Ask HN: Seeing More Techcrunch on Frontpage?

1•par•4m ago•0 comments

Website showing LLM solutions to Knuth's Problems?

1•daly•5m ago•0 comments

Unified In-Process Agent Interface for Claude Code, Codex, Kimi

https://github.com/odysa/one-agent-sdk
1•agentforce•5m ago•0 comments

DOJ proposes policy aimed at limiting state bar ethics probes into its attorneys

https://abcnews.com/US/doj-proposes-policy-aimed-limiting-state-bar-ethics/story?id=130755238
3•petethomas•6m ago•1 comments

Global Consciousness Live Data

https://gcp2.net/#home_page_live_data
1•avonmach•6m ago•0 comments

RoundsKeeper – Score tracking for board/card games (Swift/SwiftUI, iCloud sync)

https://apps.apple.com/us/app/roundskeeper/id6754217431
1•justbustr•8m ago•1 comments

Show HN: The hardware isn't changing, why not get AI to build custom drivers?

https://github.com/eli7vh/signal-chain
1•elijahlucian•11m ago•0 comments

Show HN: Scape – One-click worktrees and orchestrators for Claude Code

https://www.scape.work/
2•bgnm2000•11m ago•0 comments

The Global Coherence Initiative [video]

https://www.youtube.com/watch?v=QFqsY-DT6rg
1•avonmach•12m ago•0 comments

Show HN: Fast Chladni figure simulation in Python with NumPy vectorization

https://github.com/ratwolfzero/Chladni_Figures
2•ratwolf•19m ago•1 comments

Show HN: Session-safe uploads and artifacts for remote MCP servers

https://aakashh242.github.io/remote-mcp-adapter/
1•aakashh242•23m ago•0 comments

You Just Reveived

https://dylan.gr/1772520728
3•djnaraps•26m ago•0 comments

Nike Is Moving Jobs to Low-Wage Regions of Indonesia

https://www.propublica.org/article/nike-jobs-indonesia-living-wages
4•petethomas•30m ago•0 comments

First Open-Source PR

https://duanehilton.com/notes/your-first-open-source-pr
1•rem_one•32m ago•0 comments

Signalbase – Real-time business intelligence API for agents (x402, USDC on Base)

https://github.com/brandontan/signalbase
1•brtan881972•37m ago•0 comments

Show HN: OctoFlow–GPU-native lang, vibe-coded with human at every decision gate

https://github.com/octoflow-lang/octoflow
1•mr_octopus•37m ago•3 comments

Low data gravity for fast retrieval on K8s (2021)

https://ra-mos.medium.com/get-up-an-running-with-local-ssds-on-kubernetes-gke-p1-the-code-c6cf5ac...
2•ramoz•38m ago•0 comments

Dear Meta Smart Glasses Wearers: You're Being Watched, Too

https://gizmodo.com/dear-meta-smart-glasses-wearers-youre-being-watched-too-2000728928
3•pabs3•39m ago•1 comments

Bayesian teaching enables probabilistic reasoning in large language models

https://www.nature.com/articles/s41467-025-67998-6
2•paraschopra•39m ago•0 comments

GitHub Copilot Goldeneye model preview

https://docs.github.com/en/copilot/reference/ai-models/model-hosting
1•amusingimpala75•47m ago•1 comments

*

1•kaungsetlin•50m ago•0 comments

LexisNexis confirms data breach as hackers leak stolen files

https://www.bleepingcomputer.com/news/security/lexisnexis-confirms-data-breach-as-hackers-leak-st...
3•arkadiyt•50m ago•0 comments

Morgan Stanley Lays Off 2,500 Employees Across All Divisions

https://www.wsj.com/finance/banking/morgan-stanley-lays-off-2-500-employees-across-all-divisions-...
5•LostMyLogin•53m ago•1 comments

Learn Fundamentals, Not Frameworks

https://newsletter.techworld-with-milan.com/p/learn-fundamentals-not-frameworks
2•stosssik•53m ago•0 comments

Brainworm – Hiding in Your Context Window

https://www.originhq.com/blog/brainworm
1•dsr12•53m ago•0 comments

How does AI change Software Engineering?

https://dlants.me/ai-se.html
1•todsacerdoti•55m ago•0 comments

Iran says targeted AWS Data Centers for support of U.S. military

https://www.cnbc.com/2026/03/04/amazon-bahrain-data-centers-targeted-iran-drone-strike.html
5•johnbarron•57m ago•1 comments

Iran threatens Dimona nuclear site if Israel, US seek to topple Islamic Republic

https://www.timesofisrael.com/liveblog-march-05-2026/
3•johnbarron•57m ago•0 comments

Vibecheck – learn what you build while vibe-coding. A reality check

https://github.com/akshan-main/vibe-check/README.md
1•frutigeraerosol•58m ago•1 comments