27 May 2020
I'd love to fix them all, but I cannot. If you want to take a look @vd633 I can help you with getting started, so you can give it a try
@vd633 I found a solution
invldclass AThread(QtCore.QThread):
def run(self):
while True:
if widget.isrun:
print("thread ping")
else:
self.quit()
time.sleep(1)
I don't know why you need to quit or terminate the thread from within but could it also be that you just delete it from outside?
import time
from PySide2 import QtCore, QtWidgets
class AThread(QtCore.QThread):
def __init__(self):
super(AThread, self).__init__()
self._run = True
self._count = 0
def _sleep(self):
time.sleep(0.5)
self._count += 1
if self._count > 5:
self._run = False
def run(self):
while True:
if self._run:
print("thread ping")
self._sleep()
else:
print("okithxbyeee")
break
if __name__ == "__main__":
app = QtWidgets.QApplication()
thr = AThread()
thr.finished.connect(thr.deleteLater)
thr.start()
app.exec_()
Cristián 🥑i was just printing the "isrun" attribute
yeah, it's just variable, I just suggest checking the return of the QThread's public functions
@vd633
% python pyside-1282.py
thread ping
thread ping
thread ping
isrun = False
isRunning: True
isFinished: False
% python pyside-1282.py
thread ping
thread ping
thread ping
thread ping
thread ping
thread stopped
isRunning: True
isFinished: False
ëRiCI don't know why you need to quit or terminate the thread from within but could it also be that you just delete it from outside?
import time
from PySide2 import QtCore, QtWidgets
class AThread(QtCore.QThread):
def __init__(self):
super(AThread, self).__init__()
self._run = True
I'm not sure that "break" instead quit/terminate is normal.
Outside (from main loop) it's also doesn't work.
My cycle is endless (before window is closed - closeEvent())
Cristián 🥑terminate() is dangerous
I think terminate is dangerous when you use it from outside, because you don't know in which part of the code does it stop
Cristián 🥑in fact the terminate() documentation says: " Use QThread::wait() after terminate(), to be sure."
yeah i plan to quit first, then wait, then terminate for sure (If the thread freezes)
Maybe I'm completely wrong...I'm waiting for feedback on the patch. If you are interested : https://codereview.qt-project.org/c/pyside/pyside-setup/+/302132