an update: I found that under certain circumstances it helps to 'kick the GTK
event loop' - see below
symptom: zmq event callbacks stop after the first one
causality: unsure - the primary difference is that my code now has two sockets
and hence two of the zmq.FD/zmq.EVENTS type callbacks, and not immediately
proceeds to gtk.main()
works: just fine
-m
using pyczmq:
ctx = zctx.new()
update = zsocket.new(ctx, zmq.SUB)
zsocket.connect(update, update_uri)
cmd = zsocket.new(ctx, zmq.DEALER)
zsocket.set_identity(cmd, "%s-%d" % (name,os.getpid()))
zsocket.set_linger(cmd, 0)
zsocket.connect(cmd, cmd_uri)
self.cmd_notify = gobject.io_add_watch(zsocket.fd(cmd),
gobject.IO_IN,
self.zmq_readable, cmd,
self.cmd_readable)
self.update_notify = gobject.io_add_watch(zsocket.fd(update),
gobject.IO_IN,
self.zmq_readable, update,
self.update_readable)
# kick GTK event loop, or the zmq_readable callback gets stuck
while gtk.events_pending():
gtk.main_iteration()
# activity on one of the zmq sockets:
def zmq_readable(self, eventfd, condition, socket, callback):
while zsocket.events(socket) & zmq.POLLIN:
callback(socket)
return True
-m
Am 08.02.2013 um 20:47 schrieb Michael Haberler <[email protected]>:
>
> Am 08.02.2013 um 19:10 schrieb Michael Haberler:
>
>> Steven,
>>
>> Am 08.02.2013 um 18:39 schrieb Steven McCoy:
>>
>>> On 8 February 2013 12:31, Michael Haberler <[email protected]> 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()
> return True
>
> ....
> zmq_fd = zmq_socket.getsockopt(zmq.FD)
> gobject.io_add_watch(self.zmq_fd, gobject.IO_IN, self.zmq_callback,
> self.zmq_socket)
> gtk.main()
>
> -Michael
>
> _______________________________________________
> zeromq-dev mailing list
> [email protected]
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev