[zeromq-dev] best way to integrate pyzmq & pyqt event loops
MinRK
benjaminrk at gmail.com
Wed Apr 27 08:42:11 CEST 2011
I expect that using the zmqstream/ioloop code would not be a good fit
if you are using another (Qt or otherwise) application event loop.
Trying to use multiple Python event loops at once can get pretty
hairy. I think that working regular zmq Sockets into Qt, with a
Poller triggerig Signals/Events would be a more natural fit, but I am
not experienced with Qt.
If you do use multiple event loops, you don't want them both really
running at the same time - instead, you will probably want to run a
single iteration of the second loop (ioloop) as a periodic callback in
the first-class loop (presumably Qt here).
For ioloop, the method for running a single iteration is by
registering loop.stop as a callback:
loop = IOLoop()
stopper = PeriodicCallback(loop.stop, 0, loop)
stopper.start()
Now, any time you call loop.start(), it will only run one iteration
(you can change the period of the stopper to allow the loop to run for
a limited time, instead of a single iteration).
-MinRK
On Tue, Apr 26, 2011 at 21:12, Brian Granger <ellisonbg at gmail.com> wrote:
> Hi,
>
> Here is example of how we are doing this in IPython:
>
> https://github.com/ipython/ipython/blob/master/IPython/zmq/ipkernel.py#L450
>
> But, we are not using the IOLoop in this example. If you also want to
> use the Qt event loop for IO related things, you will probably need to
> integrate the file descriptors of the zeromq sockets into the Qt event
> loop itself. I don't really know enough about Qt to know where to
> start with this.
>
> I guess the other option would to use a periodic call in IOLoop to
> iterate the Qt event loop. That might be easier. Let us know what
> you find out.
>
> Cheers,
>
> Brian
>
> On Tue, Apr 26, 2011 at 4:56 PM, Marc Rossi <mrossi19 at gmail.com> wrote:
>> Looking for a little direction. Trying to put together a PyQt app to view
>> some of the google protobuf encoded data I'm slinging around from my C/C++
>> apps with zmq. Have the pyzmq/google protobuf stuff working no problem but
>> trying to figure out the best way to integrate the QApplication event loop
>> with the IOLoop instance I have in my script. First thoughts are to use the
>> QApplication event handler as my primary loop with idle callbacks to do my
>> zmq socket polling.
>> I'm by no means a PyQt expoert and I have to think someone has been down
>> this path before (event though searches turned up empty), so any
>> advice/direction that can be thrown my way would be much appreciated. In
>> the meantime I'm going to try and do zmq event processing in the qt
>> callbacks.
>> TIA
>> Marc
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
>
>
>
> --
> Brian E. Granger
> Cal Poly State University, San Luis Obispo
> bgranger at calpoly.edu and ellisonbg at gmail.com
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
More information about the zeromq-dev
mailing list