qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gordon Sim <g...@redhat.com>
Subject Re: Using Python Qpid Proton reactor with another event loop in the same application; messages are getting sent coalesced somehow
Date Fri, 05 May 2017 08:12:46 GMT
On 05/05/17 08:53, Jiri Danek wrote:
> Hello the list,
>
> I want to ask for help with my application. It is a rather trivial group
> chat written in Python using the Python Qpid Proton library and the Tkinter
> library for GUI.
>
> I have two problems regarding this application.
>
> First, I want to ask if I designed it correctly. I am spawning two threads
> and one is running the Tk event loop and the other is running the proton
> reactor. The on_sendable handler in the reactor is setting a
> flag self.ready_to_send = True and if this is set when the Send button is
> pushed, then the Tk thread will send all messages in a
> multiprocessing.Queue() and set flag back to False, otherwise it will add
> the new message to a queue. I could not think of any other way than using
> threads.

A proton container instance is not threadsafe, so all calls to it and 
the connections it manages should be done on the containers event thread 
(i.e. the one calling run).

You can trigger a custom 'event' to be handled on the containers event 
thread with the EventInjector. There are a couple of examples that show 
this pattern that may help:

 
https://git1-us-west.apache.org/repos/asf/qpid-proton/repo?p=qpid-proton.git;a=blob;f=examples/python/db_recv.py;hb=HEAD

and
 
https://git1-us-west.apache.org/repos/asf/qpid-proton/repo?p=qpid-proton.git;a=blob;f=examples/python/db_send.py;hb=HEAD

   or 
https://git1-us-west.apache.org/repos/asf/qpid-proton/repo?p=qpid-proton.git;a=blob;f=examples/python/tx_recv_interactive.py;hb=HEAD


> Second, the chat is not working properly now. What seems to be happening is
> that the reactor is not sending the messages the moment
> self.sender.send(message) is called, but they are sent in bunches of two,
> three or even more. Anybody has any idea what I might be doing wrong? I am
> rather certain it is nothing I do with the multiprocessing.Queue() because
> same behavior happens if I just call reactor.sender.send() directly,
> disregarding the ready_to_send flag and anything.
>
> The application is at https://github.com/jdanekrh/reactive_messaging_app,
> see a quick demo at https://www.youtube.com/watch?v=OGGdeEx7nZ8 (31
> seconds) which shows the behavior I described in my second question.
>
> Thanks for any help,
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Mime
View raw message