[zeromq-dev] How to make recv() non blocking

Antonio Teixeira eagle.antonio at gmail.com
Tue Apr 3 11:39:48 CEST 2012


You can find here a couple of examples :

https://github.com/zeromq/pyzmq/blob/master/examples/poll/pubsub.py

https://github.com/zeromq/pyzmq/tree/master/examples/poll

And the API
http://zeromq.github.com/pyzmq/api/generated/zmq.core.poll.html

Just take into consideration that if you want to use Gevent or greenlets ,
etcn they will block when using poll :)



2012/4/3 Ronald Swain <proj_symbian at live.com>

>  Hello Antonio,
>
> thanks a lot for quickest reply :-)
>
> I got your way of using NOBLOCK, but can you brief me more about how i can
> use zmq.poll here using the POLLIN and POLLOUT events.
>
> Regards
> Ronald
>
> ------------------------------
> Date: Tue, 3 Apr 2012 09:27:24 +0000
> From: eagle.antonio at gmail.com
> To: zeromq-dev at lists.zeromq.org
> Subject: Re: [zeromq-dev] How to make recv() non blocking
>
> 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
>
>
>
> _______________________________________________ zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
> _______________________________________________
> 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/282b42c7/attachment.htm>


More information about the zeromq-dev mailing list