PubSub and working thread

Hi,

I have an application where I need to communicate between a working thread and wx frames.
Threads can't directly call UI API so I usually do this with wx events. The working thread sends messages to a frames using wx.Event.
It works but this not as simple as with PubSub.
My concern is about the thread safety of PubSub. Is it safe to publish from a working thread and subscribe from wx frames ?

Regards,
Nicolas

PubSub doesn’t do anything with, nor is aware of threads. This means that the subscriber will be called in whatever thread was active when the message was sent. It’s not difficult to work around however, as the subscribed function could simply use wx.CallAfter to schedule a call to some other function to do the real work.

···

On Wednesday, April 3, 2019 at 1:28:01 PM UTC-7, Nicolas Pinault wrote:

Hi,

I have an application where I need to communicate between a working
thread and wx frames.

Threads can’t directly call UI API so I usually do this with wx events.
The working thread sends messages to a frames using wx.Event.

It works but this not as simple as with PubSub.

My concern is about the thread safety of PubSub. Is it safe to publish
from a working thread and subscribe from wx frames ?

Robin

That’s what I thought but I wanted to be sure.
Thanks for the tip :slight_smile:
Nicolas

···

Le 04/04/2019 à 00:18, Robin Dunn a
écrit :

    On Wednesday, April 3, 2019 at 1:28:01 PM UTC-7,

Nicolas Pinault wrote:

      Hi,




      I have an application where I need to communicate between a

working

      thread and wx frames.


      Threads can't directly call UI API so I usually do this with

wx events.

      The working thread sends messages to a frames using wx.Event.


      It works  but this not as simple as with PubSub.


      My concern is about the thread safety of PubSub. Is it safe to

publish

      from a working thread and subscribe from wx frames ?
      PubSub doesn't do anything with, nor is aware of threads.

This means that the subscriber will be called in whatever
thread was active when the message was sent.

      It's not difficult to work around however, as the

subscribed function could simply use wx.CallAfter to schedule
a call to some other function to do the real work.

Robin

  You received this message because you are subscribed to the Google

Groups “wxPython-dev” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxPython-dev+unsubscribe@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).