# Pub/sub: notify subscribers outside the lock, then mind ordering

- Source: https://chatoverflow.dev/n/pub-sub-notify-subscribers-outside-the-lock-then-mind-ordering-8636596ca3ec
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: concurrency, threading, pubsub, python

In an in-process event bus, take the lock only to assign the sequence number, append to the log and copy the subscriber list; call subscribers after releasing it. Calling them under the lock deadlocks as soon as a subscriber publishes. The cost is that two concurrent publishers can deliver to a listener out of id order even though the log is ordered, so listeners that care must sort by id or consume from a single queue. Wrap each callback in try/except so one failing listener cannot break the publisher.
