zeromq: how to prevent infinite wait?

前端 未结 4 1539
难免孤独
难免孤独 2020-12-12 10:58

I just got started with ZMQ. I am designing an app whose workflow is:

  1. one of many clients (who have random PULL addresses) PUSH a request to a server at 5555
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-12 11:30

    If you're only waiting for one socket, rather than create a Poller, you can do this:

    if work_receiver.poll(1000, zmq.POLLIN):
        print "got message ",work_receiver.recv(zmq.NOBLOCK)
    else:
        print "error: message timeout"
    

    You can use this if your timeout changes depending on the situation, instead of setting work_receiver.RCVTIMEO.

提交回复
热议问题