Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-3200

Inheritance with overridden Slot method breaks thread affinity

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Out of scope
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.8.0
    • PySide
    • None

      I looked at PYSIDE-3124, but this appears to be a separate issue since all the receivers here are @Slot-decorated methods.

       

      I have attached a small example, where a signal from an object in the GUI thread is sent over to a worker object in a separate thread, and another signal is sent from the worker back to a third object the GUI thread.

       

      If the receiving object is a derived class, where it and the base class both decorate their method with @Slot, the thread affinity is disregarded, and the method is called from the wrong thread.  If the @Slot decorator is removed from the base class method definition, the derived class functions as expected.

       

      Output with 

      USE_DERIVED = False
      Python 3.10.2 win32
      Qt 6.8.0 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2022) [Python limited API 3.10.2]
      gui_thread=<PySide6.QtCore.QThread(0x213449ef360, name = "Qt mainThread") at 0x000002134667E740>
      other_thread=<PySide6.QtCore.QThread(0x21344a184f0) at 0x000002134667E7C0>
      echo test:  <PySide6.QtCore.QThread(0x21344a184f0) at 0x000002134667E7C0>
      rx test

       

      with 

      USE_DERIVED = True
      Python 3.10.2 win32
      Qt 6.8.0 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2022) [Python limited API 3.10.2]
      gui_thread=<PySide6.QtCore.QThread(0x22c83b24250, name = "Qt mainThread") at 0x0000022C857FE740>
      other_thread=<PySide6.QtCore.QThread(0x22c83b4e7f0) at 0x0000022C857FE7C0>
      echo test:  <PySide6.QtCore.QThread(0x22c83b4e7f0) at 0x0000022C857FE7C0>
      rx test modified
      QObject: Cannot create children for a parent that is in a different thread.
      (Parent is DerivedReceiverObject(0x22c83b4e0b0), parent's thread is QThread(0x22c83b24250), current thread is QThread(0x22c83b4e7f0)

       

        1. thread_inheritance.py
          2 kB
        2. pyside3200.py
          3 kB
        3. pyside3200_log.txt
          4 kB
        4. pyside3200_diag.diff
          6 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            crmaurei Cristian Maureira-Fredes
            tbatkiewicz Tom Batkiewicz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes