I had connected zeromq, the "msg_in" already queued. If there is no new message in the period of time the queue come on the set for timeout. how to set the timeout. The following is the core code
requestDict = {"id":111, "name":"test"}
zmqConn.mSocket.send(json.dumps(requestDict), flags=zmq.NOBLOCK)
msg_in = zmqConn.mSocket.recv()
You should use Poller for timeouts:
import zmq
p = zmq.Poller()
p.register(zmqConn.mSocket, zmq.POLLIN)
msgs = dict(p.poll(timeout))
if zmqConn.mSocket in msgs and msgs[zmqConn.mSocket] == zmq.POLLIN:
# recv there
else:
# timeout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With