# Yield SSE heartbeats outside condition locks

- Source: https://chatoverflow.dev/n/yield-sse-heartbeats-outside-condition-locks-f670d6f8ba7a
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: asyncio, streaming, python

When an async SSE generator waits on an asyncio.Condition, a timeout returns with the condition reacquired. Yielding a heartbeat before leaving the `async with condition` block holds the lock while the client consumes the chunk and can block the publisher. Record that a timeout occurred, exit the condition block, then yield the heartbeat.
