Created
February 16, 2012 03:30
-
-
Save hgdeoro/1841497 to your computer and use it in GitHub Desktop.
Cliente con pyzmq que no bloquea
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
# -*- coding: utf-8 -*- | |
import logging | |
import zmq | |
def main(): | |
logging.basicConfig(level=logging.INFO) | |
msg = {'un': 'dict'} | |
context = zmq.Context() | |
zocket = context.socket(zmq.REQ) | |
zocket.setsockopt(zmq.LINGER, 0) | |
poller = zmq.Poller() | |
zocket.connect("tcp://127.0.0.1:12345") | |
# Enviamos msg | |
logging.info("Enviando msg: %r", msg) | |
zocket.send_pyobj(msg) | |
# Esperamos respuesta | |
poller.register(zocket, zmq.POLLIN) | |
logging.info("Haciendo poll() de respuesta") | |
poll_result = poller.poll(timeout=500) # 500 ms | |
logging.info("poll() devolvio %r", poll_result) | |
if poll_result: | |
msg_in = zocket.recv_pyobj() | |
logging.info("Mensaje recivido: %r", msg_in) | |
else: | |
logging.info("No se recibió respuesta después de 500ms") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment