Created
October 10, 2014 22:43
-
-
Save Lothiraldan/b1557ea2a151ffb2c9b3 to your computer and use it in GitHub Desktop.
This file contains 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
def recv_future(zmqstream): | |
''' Retruns future for recv on zmqstream | |
''' | |
future = Future() | |
def _finish(reply): | |
future.set_result(reply) | |
zmqstream.on_recv(_finish) | |
return future | |
def poll_sync(): | |
context = zmq.Context().instance() | |
socket = context.socket(zmq.REQ) | |
socket.connect("tcp://localhost:9802") | |
socket.send('Ping'.encode('utf-8')) | |
result = socket.recv() | |
socket.close() | |
return result | |
@gen.coroutine | |
def poll_async(): | |
context = zmq.Context().instance() | |
socket = context.socket(zmq.REQ) | |
socket.connect("tcp://localhost:9802") | |
zmqstream = ZMQStream(socket) # Required for ZMQ | |
zmqstream.send('Ping'.encode('utf-8')) | |
result = yield recv_future(zmqstream) | |
zmqstream.close() | |
raise gen.Return(result[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment