[zeromq-dev] GTK event loop integration, anybody?
mail17 at mah.priv.at
Fri Feb 8 20:47:11 CET 2013
Am 08.02.2013 um 19:10 schrieb Michael Haberler:
> Am 08.02.2013 um 18:39 schrieb Steven McCoy:
>> On 8 February 2013 12:31, Michael Haberler <mail17 at mah.priv.at> wrote:
>> I'm looking to into integrating zmq with a pyGTK (eventually pygobject) application, including event loop integration
>> any pointers to a working example?
>> You can wrap around zmq_poll.
> sorry, 'wrap around' was a tad above my pay grade ;)
> I see the following options:
> 1. poll from the idle loop (g_idle_add() or py equivalent)
> 2. poll in a glib timer event (g_timeout_add() or python equivalent)
> 3. use zmq_getsockopt/ZMQ_FD to retrieve the file descriptor associated with the socket and have the gtk main loop issue a callback on FD events
> 4. use the pyzmq gevent route
> 5. somehow have separate event loops (not sure if this is possible)
> 3) I'd feel confortable with rolling myself
> 5) ? dunno.
> 4) uses the dreaded libevent under the gevent Python package, so I'd rather not use that
> 1+2: not my style ;)
> is 3) reasonable? if not, what else?
this works fine for a start:
import gobject, zmq
def zmq_callback(self, fd, condition, zmq_socket):
while zmq_socket.getsockopt(zmq.EVENTS) & zmq.POLLIN:
(channel, msg) = zmq_socket.recv_multipart()
zmq_fd = zmq_socket.getsockopt(zmq.FD)
gobject.io_add_watch(self.zmq_fd, gobject.IO_IN, self.zmq_callback, self.zmq_socket)
More information about the zeromq-dev