title: Python multithreading with pypubsub and wx
body: <p>I have a program that is structured like this:</p>
  <p><a href="https://i.stack.imgur.com/UZSg9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UZSg9.png" alt="enter image description here" /></a></p>
  <p>The <code>GUI</code> is made with wxPython and is in the Main Thread. After launching the application, the GUI thread creates <code>Thread1</code>, which creates a static class <code>Class1</code>, which creates <code>Thread2</code>.</p>
  <p>Thread1 talks with the GUI using <code>wx.PostEvent</code>, and everything works fine. I need Thread1 to communicate also with Thread2, so I decided to do that using pyPubSub. Thread2 needs to work in the background because it contains some operations that are executed periodically, but it contains also a function (let's say <code>my_func()</code>) that Thread1 needs to call on certain events. I decided to put <code>my_func()</code> in Thread2 because I don't want it to stop the execution of Thread1, but that's exactly what happens: in Thread1 after some events I use <code>pub.sendMessage(&quot;events&quot;, message=&quot;Hello&quot;)</code> to trigger <code>my_func()</code>; Thread2 is structured like this:</p>
  <pre><code>class Thread2(Thread)
      def __init__(self, parent):
          super().__init__()
          self.parent = parent
          pub.subscribe(self.my_func, &quot;events&quot;)
      
      def run(self):
          while True:
          # do stuff
      
      def my_func(self, message):
          # do other stuff using the message
          # call parent functions
  </code></pre>
  <p>The parent of Thread2 is Class1, so when I create the thread in Class1 I do:</p>
  <pre><code>self.t2 = Thread2(self)
  self.t2.start()
  </code></pre>
  <p>Why does Thread2 stops the execution of Thread1?</p>