[zeromq-dev] How to make recv() non blocking
Antonio Teixeira
eagle.antonio at gmail.com
Tue Apr 3 11:27:24 CEST 2012
Hello Ronald.
This works for me :)
recevSock.recv(flags=zmq.NOBLOCK)
This will rase and exception you will have to handle it :)
so
try:
recevSock.recv(flags=zmq.NOBLOCK)
except zmq.core.error.ZMQError,e:
if str(Resource temporarily unavailable) in e:
# Socket not ready
return None
else:
# Oopsy other error re-raise
raise
You can also use zmq.poll to handle the POLLIN POLLOUT Events :)
2012/4/3 Ronald Swain <proj_symbian at live.com>
> Hello All,
>
> After a long time i have a question and it seems to be the simple one.
>
> I am using following code to receive something using PyZMQ:
>
> import zmq
> zmqContext = zmq.Context()
> recevSock = zmqContext.socket(zmq.SUB)
> recevSock.connect('address')
> recevSock.setsockopts(zmq.SUBSCRIBE.' ')
> recevSock.recv()
>
> But the call to recv is blocking my code, so what is the best routine to
> make that non blocking, i read the docs and they say that i have to set a
> FLAG NOBLOCK in the method, but when i do so :
>
> recevSock.recv(flags=1)
>
> it throws exception: zmq.core.error.ZMQError: Resource temporarily
> unavailable
>
> Can any body please help me to move forward.
>
> Regards,
> Ronald
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120403/6c8a31a3/attachment.htm>
More information about the zeromq-dev
mailing list