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

Slot executing in wrong QThread

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.15.0
    • Fix Version/s: None
    • Component/s: PySide
    • Labels:
      None
    • Environment:
      Python 3.7.7
    • Platform/s:
      macOS
    • Commits:
      3c551005dcb8de4bb083aa934a8fdff1298f14f9 (pyside/pyside-setup/5.15)

      Description

      I came across another weird error with the @Slot decorator in combination with QThread. Here's a minimal example to reproduce it:

      import sys
      from PySide2.QtCore import QObject, QThread, Slot
      from PySide2.QtWidgets import QApplication
      
      class Worker(QObject):
      
          @Slot()
          def do_work(self):
              print(f'Running on {QThread.currentThread().objectName()}')
      
      
      class SubWorker(Worker):
          pass
      
      
      app = QApplication([])
      app.thread().setObjectName('Main Thread')
      worker_thread = QThread()
      worker_thread.setObjectName('Worker Thread')
      
      worker = Worker()
      #worker = SubWorker()
      
      worker.moveToThread(worker_thread)
      worker_thread.started.connect(worker.do_work)
      worker_thread.start()
      
      sys.exit(app.exec_())
      

      If I instantiate Worker as above, it outputs "Running on Worker Thread" as expected. However, with SubWorker the slot executes on the main thread instead, i.e. giving the output "Running on Main Thread".

      It behaves correctly with both classes if I simply omit the @Slot decorator. I also tested the same code with PyQt5 and pyqtSlot() where it works correctly in both cases.

       

       

        Attachments

        1. pyside1354_diag.diff
          22 kB
        2. pyside1354_log.txt
          4 kB
        3. pyside1354.py
          1 kB

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              kleint Friedemann Kleint
              Reporter:
              3rdcycle Lukas Heiniger
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes