Created
October 4, 2015 12:50
-
-
Save litnimax/b96563163c3ce1e09561 to your computer and use it in GitHub Desktop.
litnimax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import zmq | |
| # None of these operations will block, regardless of peer: | |
| context = zmq.Context() | |
| socket = context.socket(zmq.REQ) | |
| socket.setsockopt(zmq.LINGER, 0) | |
| socket.connect("tcp://127.0.0.1:12346") | |
| socket.send_json({"msg": "testmsg"}) # send can block on other socket types, so keep track | |
| # use poll for timeouts: | |
| poller = zmq.Poller() | |
| poller.register(socket, zmq.POLLIN) | |
| if poller.poll(10*1000): # 10s timeout in milliseconds | |
| msg = socket.recv_json() | |
| else: | |
| raise IOError("Timeout processing auth request") | |
| # these are not necessary, but still good practice: | |
| socket.close() | |
| context.term() | |
| sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment