pubsub from threads

Hi,

Updating the GUI from threads in wx is not supported, so I always believed you could for example use pubsub to "signal" GUI-update functions. I tried this today, but it seems like it will randomly hang the GUI just like if you called the GUI-update functions directly.

To recap: using pubsub from a thread to signal updates (to the GUI) and in the pubsub signal handler calling the GUI-update function, is just as bad as calling the GUI-update functions directly from the thread. Is this a correct assumption on my part?

Thanks,
Frank

Hello Frank:
I have had success by using:

wx.CallAfter(Publisher.sendMessage,
                        topic='SomeTopic',
                        data=SomeData)

···

On Jan 14, 2008 3:48 PM, Frank Aune <frank.aune@broadpark.no> wrote:

Hi,

Updating the GUI from threads in wx is not supported, so I always
believed you could for example use pubsub to "signal" GUI-update
functions. I tried this today, but it seems like it will randomly hang
the GUI just like if you called the GUI-update functions directly.

To recap: using pubsub from a thread to signal updates (to the GUI)
and in the pubsub signal handler calling the GUI-update function, is
just as bad as calling the GUI-update functions directly from the
thread. Is this a correct assumption on my part?

Thanks,
Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

--
Best Regards,
Michael Moriarity

You cannot use pubsub because you will call your main gui in the
thread context of your worker thread. Which is basically the same as
just calling GUI elements from inside your thread. I would suggest
using a thread safe QUEUE where you post data in, and use OnIdle or
any other mechanism to read messages back inside the GUI thread. Also
postevent will work, but then you will use GUI related stuff in a
working thread and it's not really decoupled.

- Jorgen

···

On Jan 15, 2008 9:55 AM, Frank Aune <Frank.Aune@broadpark.no> wrote:

On Monday 14 January 2008 23:41:23 Michael Moriarity wrote:
> Hello Frank:
> I have had success by using:
>
> wx.CallAfter(Publisher.sendMessage,
> topic='SomeTopic',
> data=SomeData)

But won't this contradict the entire point of pubsub, since you want to keep
your model separated from wx?

I've tried calling wx.CallAfter on the function performing the GUI update, but
still the GUI will randomly hang.

Cheers,

Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Thanks for the reply - I was afraid of this. IMHO this is a huge limitation
for pubsub.

Can the issue be worked around by calling wx.CallAfter on all functions
updating the GUI? I'm using this solution now, and it seems to be working,
however from experience such features can blow up in your face after some
time.

Cheers,
Frank

···

On Tuesday 15 January 2008 13:09:31 Jorgen Bodde wrote:

You cannot use pubsub because you will call your main gui in the
thread context of your worker thread. Which is basically the same as
just calling GUI elements from inside your thread. I would suggest
using a thread safe QUEUE where you post data in, and use OnIdle or
any other mechanism to read messages back inside the GUI thread. Also
postevent will work, but then you will use GUI related stuff in a
working thread and it's not really decoupled.