I have a simple ZMQ
program that establishes a zmq.PUSH
socket, connects
, and then tries to send messages.
import zmq
zcontext = zmq.Context()
zsock = zcontext.socket(zmq.PUSH)
zsock.connect("tcp://localhost:12345")
with open(sys.argv[1]) as f:
for line in f:
zsock.send(line)
This works fine when the other side is there. But if there's any problems with the listener on the other side (e.g. forgot to start listener, or I connected to wrong port), it just hangs after it tries to send about 1000 messages (depends on size of the default queue).
What's the right thing to do? If there's any issue with other side, I'd rather just print an error message and exit gracefully.