<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/what-python-s-asyncio-primitives-get-wrong-about-shared-state-70bxp74ka" -->

---
title: What Python's asyncio primitives get wrong about shared...
description: A deep dive into coordinating concurrent Python asyncio tasks around shared state, walking through why polling, asyncio.Event, and asyncio.Condition all fail...
canonical: https://daily.dev/posts/what-python-s-asyncio-primitives-get-wrong-about-shared-state-70bxp74ka
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: What Python's asyncio primitives get wrong about shared state | daily.dev
og:description: A deep dive into coordinating concurrent Python asyncio tasks around shared state, walking through why polling, asyncio.Event, and asyncio.Condition all fail...
og:url: https://daily.dev/posts/what-python-s-asyncio-primitives-get-wrong-about-shared-state-70bxp74ka
og:image: https://api.daily.dev/og/posts/70bxp74Ka.png
og:image:alt: What Python's asyncio primitives get wrong about shared state
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# What Python's asyncio primitives get wrong about shared state

**[Inngest Blog](https://daily.dev/sources/inngest)** · 11 min read · 0 upvotes · 0 comments

## Summary

A deep dive into coordinating concurrent Python asyncio tasks around shared state, walking through why polling, asyncio.Event, and asyncio.Condition all fail under fast state transitions (the 'lost update' problem where a consumer wakes up after the value has already changed again). The fix is a ValueWatcher class that gives each consumer its own asyncio.Queue, buffering every transition so no intermediate state is missed. The post includes a production-ready implementation with thread safety, generic typing, timeouts, conditional sets, and callback APIs, built while developing Inngest's Python SDK for WebSocket connection management.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.inngest.com/blog/no-lost-updates-python-asyncio>

## Questions this post answers

### Why does asyncio.Condition miss a state transition when the value changes twice quickly in Python?

asyncio.Condition's notify_all() schedules wakeups but doesn't run consumers immediately, so if the value changes again before the waiting coroutine actually runs, the consumer re-evaluates its predicate against the new current value instead of the one that triggered the notification. This causes a lost update where an intermediate state like 'closing' is silently skipped if the state moves to 'closed' before the consumer wakes up.

_Anyone coordinating async state transitions can compare pitfalls of asyncio primitives on daily.dev before picking one._

### How can I avoid missing intermediate state changes when multiple asyncio tasks watch shared state?

Give each consumer its own asyncio.Queue and push every (old, new) value transition into all registered queues whenever the value changes, rather than only notifying about the current value. Each consumer then drains its own queue and checks every transition individually, so no intermediate state, even one that occurs within a single event loop tick, is ever missed.

_Developers debugging flaky async coordination bugs can dig into patterns like this on daily.dev._

### Why doesn't asyncio.Event scale well for coordinating multiple states in Python?

asyncio.Event only holds a boolean set/unset value, so waiting on multiple distinct states requires creating a separate Event object for each one, with the setter manually calling set() or clear() on every relevant event whenever the state changes. Forgetting to set or clear one of them causes a consumer to block forever, and the coordination logic becomes error-prone as more states are added.

_Teams weighing asyncio primitives for state coordination can compare tradeoffs on daily.dev._

## Similar posts on daily.dev

- [7 Async Patterns for Running Agents Concurrently in Python](https://daily.dev/posts/7-async-patterns-for-running-agents-concurrently-in-python-rwlsuu2a6) · Machine Learning Mastery · 1 upvotes · 0 comments
- [The Tokio/Rayon Trap and Why Async/Await Fails Concurrency](https://daily.dev/posts/the-tokio-rayon-trap-and-why-async-await-fails-concurrency-v76c9exib) · Hacker News · 11 upvotes · 1 comments
- [Fire and forget \(or never\) with Python’s asyncio](https://daily.dev/posts/fire-and-forget-or-never-with-python-s-asyncio-o7sj2kagn) · Planet Python · 0 upvotes · 0 comments
- [Invisible Failures: The Python Server Mistake We Made in Production](https://daily.dev/posts/invisible-failures-the-python-server-mistake-we-made-in-production-ujme9h4jg) · ITNEXT · 1 upvotes · 0 comments

---

Tags: [#inngest](https://daily.dev/tags/inngest), [#python](https://daily.dev/tags/python)

[View this post on daily.dev](https://daily.dev/posts/what-python-s-asyncio-primitives-get-wrong-about-shared-state-70bxp74ka)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"What Python's asyncio primitives get wrong about shared state","url":"https://daily.dev/posts/what-python-s-asyncio-primitives-get-wrong-about-shared-state-70bxp74ka","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/what-python-s-asyncio-primitives-get-wrong-about-shared-state-70bxp74ka"},"datePublished":"2026-09-13T19:57:34.092Z","dateModified":"2026-10-15T02:22:58.401Z","description":"A deep dive into coordinating concurrent Python asyncio tasks around shared state, walking through why polling, asyncio.Event, and asyncio.Condition all fail...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/48992a61eb72e188e74f0967b6c7fde1?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/48992a61eb72e188e74f0967b6c7fde1?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Inngest Blog","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Inngest Blog","logo":"https://media.daily.dev/image/upload/s--ieZKUa5y--/c_limit,w_256/f_auto,q_auto/v1789329423/logos/inngest?_a=BAMAMicg0","url":"https://daily.dev/sources/inngest"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/what-python-s-asyncio-primitives-get-wrong-about-shared-state-70bxp74ka","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"inngest,python","timeRequired":"PT11M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Inngest Blog","item":"https://daily.dev/sources/inngest"},{"@type":"ListItem","position":3,"name":"What Python's asyncio primitives get wrong about shared state"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/what-python-s-asyncio-primitives-get-wrong-about-shared-state-70bxp74ka#faq","mainEntity":[{"@type":"Question","name":"Why does asyncio.Condition miss a state transition when the value changes twice quickly in Python?","acceptedAnswer":{"@type":"Answer","text":"asyncio.Condition's notify_all() schedules wakeups but doesn't run consumers immediately, so if the value changes again before the waiting coroutine actually runs, the consumer re-evaluates its predicate against the new current value instead of the one that triggered the notification. This causes a lost update where an intermediate state like 'closing' is silently skipped if the state moves to 'closed' before the consumer wakes up. Anyone coordinating async state transitions can compare pitfalls of asyncio primitives on daily.dev before picking one."}},{"@type":"Question","name":"How can I avoid missing intermediate state changes when multiple asyncio tasks watch shared state?","acceptedAnswer":{"@type":"Answer","text":"Give each consumer its own asyncio.Queue and push every (old, new) value transition into all registered queues whenever the value changes, rather than only notifying about the current value. Each consumer then drains its own queue and checks every transition individually, so no intermediate state, even one that occurs within a single event loop tick, is ever missed. Developers debugging flaky async coordination bugs can dig into patterns like this on daily.dev."}},{"@type":"Question","name":"Why doesn't asyncio.Event scale well for coordinating multiple states in Python?","acceptedAnswer":{"@type":"Answer","text":"asyncio.Event only holds a boolean set/unset value, so waiting on multiple distinct states requires creating a separate Event object for each one, with the setter manually calling set() or clear() on every relevant event whenever the state changes. Forgetting to set or clear one of them causes a consumer to block forever, and the coordination logic becomes error-prone as more states are added. Teams weighing asyncio primitives for state coordination can compare tradeoffs on daily.dev."}}]}
```

