You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Jiri Danek <jd...@redhat.com> on 2017/05/05 07:53:42 UTC

Using Python Qpid Proton reactor with another event loop in the same application; messages are getting sent coalesced somehow

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.

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,
-- 
Jiří Daněk

Re: Using Python Qpid Proton reactor with another event loop in the same application; messages are getting sent coalesced somehow

Posted by Gordon Sim <gs...@redhat.com>.
On 05/05/17 09:40, Jiri Danek wrote:
> So here is fixed video which shows it working properly:
> https://youtu.be/uq0BGYvwMkg

Very nice!

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


Re: Using Python Qpid Proton reactor with another event loop in the same application; messages are getting sent coalesced somehow

Posted by Jiri Danek <jd...@redhat.com>.
On Fri, May 5, 2017 at 10:12 AM, Gordon Sim <gs...@redhat.com> wrote:

>
> 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:


That's it!

So here is fixed video which shows it working properly:
https://youtu.be/uq0BGYvwMkg

Thank you for your help. I saw some of the examples before, but I haven't
realized that is what I have to do here.
-- 
Jiří Daněk

Re: Using Python Qpid Proton reactor with another event loop in the same application; messages are getting sent coalesced somehow

Posted by Gordon Sim <gs...@redhat.com>.
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