Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经连接了 zeromq,“msg_in”已经排队。如果在该时间段内没有新消息队列到来,则设置超时。如何设置超时。以下是核心代码
requestDict = {"id":111, "name":"test"} zmqConn.mSocket.send(json.dumps(requestDict), flags=zmq.NOBLOCK) msg_in = zmqConn.mSocket.recv()
您应该使用 Poller 进行超时:
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