If you are using zeromq> = 3.0, you can set the RCVTIMEO socket option:
client_receiver.RCVTIMEO = 1000 # in milliseconds
But in general, you can use indicators:
poller = zmq.Poller() poller.register(client_receiver, zmq.POLLIN) # POLLIN for recv, POLLOUT for send
And poller.poll() takes a timeout:
evts = poller.poll(1000)
evts will be an empty list if nothing is received.
You can poll with zmq.POLLOUT to see if you can send the message.
Or, to handle a peer case that could have been a failure, a:
worker.send(msg, zmq.NOBLOCK)
it may be enough that it will always be returned immediately - raising ZMQError (zmq.EAGAIN) if the sending cannot be completed.
minrk Sep 24 '11 at 16:33 2011-09-24 16:33
source share