Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
None
-
5.15.0
-
None
-
Python 3.7.7
-
-
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
Issue Links
- duplicates
-
PYSIDE-249 Adding QtCore.Slot() decorator to base class function influences which thread executes slot in a derived class.
- Closed