PySide2: problem with starting QThread with a signal when using debugger Follow
Answered
The issue first reported in post PySide: problem with starting QThread with a signal when using debugger is now available in:
PyCharm 2019.2 (Community Edition)
Build #PC-192.5728.105, built on July 23, 2019
Runtime version: 11.0.3+12-b304.10 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 7 6.1
Pyside2 (5.13) and Python 3.7
Please sign in to leave a comment.
Hi,
Could you please provide sample code for reproducing?
The one from this post isn't exactly the same since it uses Python 2.7.15 and different PyCharm version.
Below is a piece of code I copied, and modified, from Stack Overflow using three different methods of threading. QObject.moveToThread() does not run in a new thread in 2019.2. The code below works fine in:
PyCharm 2018.3.7 (Community Edition)
Build #PC-183.6156.16, built on July 9, 2019
JRE: 1.8.0_152-release-1343-b28 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 7 6.1
####### start code ###############
import sys
import time
from PySide2.QtCore import (QCoreApplication, QObject, QRunnable, QThread,
QThreadPool, Signal)
# Subclassing QThread
# http://qt-project.org/doc/latest/qthread.html
class AThread(QThread):
def run(self):
count = 0
while count < 5:
time.sleep(1)
print("A Increasing")
count += 1
# Subclassing QObject and using moveToThread
# http://blog.qt.digia.com/blog/2007/07/05/qthreads-no-longer-abstract
class SomeObject(QObject):
finished = Signal()
def long_running(self):
count = 0
while count < 5000:
time.sleep(1)
print("B Increasing")
import pydevd;pydevd.settrace(suspend=False)
count += 1
self.finished.emit()
# Using a QRunnable
# http://qt-project.org/doc/latest/qthreadpool.html
# Note that a QRunnable isn't a subclass of QObject and therefore does
# not provide signals and slots.
class Runnable(QRunnable):
def run(self):
count = 0
app = QCoreApplication.instance()
while count < 5:
print("C Increasing")
time.sleep(1)
count += 1
app.quit()
def using_q_thread():
app = QCoreApplication([])
thread = AThread()
thread.finished.connect(app.exit)
thread.start()
sys.exit(app.exec_())
def using_move_to_thread():
app = QCoreApplication([])
objThread = QThread()
obj = SomeObject()
obj.moveToThread(objThread)
obj.finished.connect(objThread.quit)
objThread.started.connect(obj.long_running)
objThread.finished.connect(app.exit)
objThread.start()
sys.exit(app.exec_())
def using_q_runnable():
app = QCoreApplication([])
runnable = Runnable()
QThreadPool.globalInstance().start(runnable)
sys.exit(app.exec_())
if __name__ == "__main__":
# using_q_thread()
using_move_to_thread()
# using_q_runnable()
May I ask you to upload it as a file to https://uploads.services.jetbrains.com/ and let me know the name of the file so I have it with correct formatting?
I have uploaded the file and it is called "so_thread1.py"
Thank you!
I filed an issue to our tracker https://youtrack.jetbrains.com/issue/PY-37222 so the responsible developer can take a look.
It seems that it can be related to https://youtrack.jetbrains.com/issue/PY-24229, but let's see what the developer says.