title: QThread exception management and thread race
body: <p>I have a GUI (PySide) application that uses QThread. I have a signal in my QThread that is emitted when an exception occurs so that I can handle the exception in the main thread. However, the rest of the function starting the thread is still executed. I tried the <code>wait</code> function to block the execution but it does not work. Here is my implementation:</p>
  
  <p><strong>QThread daughter</strong></p>
  
  <pre><code>class LongTaskThread(QtCore.QThread):
      task_finished = QtCore.Signal()
      task_failed = QtCore.Signal(Exception)
  
      def __init__(self, allow_log=True, test_mode=False, parent=None):
          QtCore.QThread.__init__(self, parent)
  
      def run(self):
          self.task_failed.emit(Exception())
  
      def wait_with_gui_refresh(self):
          while self.isRunning():
              time.sleep(0.1)
              if not self.test_mode:
                  QtGui.QApplication.processEvents()
  </code></pre>
  
  <p><strong>Main thread</strong></p>
  
  <pre><code>def test():
     my_thread = LongTaskThread()
     my_thread.task_finished.connect(on_finished)
     my_thread.task_failed.connect(on_failed)
     my_thread.start()
     # my_thread.wait()    &lt;---- tentative 1
     # my_thread.wait_with_gui_refresh()    &lt;---- tentative 2
     print('bla bla bla bla')
  
  def on_finished)():
     pass
  
  def on_failed(err):
    raise err
  </code></pre>
  
  <p>I expected that the <code>print</code> would never been hit, but whether I use the <code>wait</code> function or the <code>wait_with_gui_refresh</code> function, or nothing, the print is always printed.</p>
  
  <p>How to stop the test function when an exception is raised inside the QThread ?</p>