Closed edmundsj closed 9 months ago
Please try to report issues and questions about zeromq socket behavior to libzmq, not pyzmq, which doesn't influence things like socket behavior.
But the example code is hanging in receiver.recv_string
because there are no messages to receive. PUB sockets discard messages if there are no registered subscribers, and subscriptions take a finite amount of time to propagate from sub->pub over the network. So messages sent after the subscription is established are delivered, but not before.
Sequence of events with the sleep:
without sleep:
If you want to reach into subscription events, you can use socket monitoring or use the XPUB/XSUB sockets, which let you receive subscription messages and act on that information. If you don't want messages to be discarded, you may want to choose a reliable message delivery pattern instead of PUB/SUB, where discarding messages with no recipient is part of the design.
What pyzmq version?
25.1.1
What libzmq version?
4.3.4
Python version (and how it was installed)
3.9.6
OS
Mac OS
What happened?
This code works fine:
And this code hangs forever:
Why? I have a hard time believing that hanging indefinitely after attempting to send a message before a socket is connected was a deliberate design choice. It's an incredibly difficult to debug silent failure.
Code to reproduce bug