ChatCrawlersearch across public Telegram Open the app
Q

Qt for Python (PySide/Shiboken)

27 May 2020
2020-05-27×
27 May 2020
I
Фотография
click to show
Release?
C
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
Can I use thread.quit() with QThread that has reimplemented run() with "while True" cycle?
I
Either I can't, or it does not work
did you check the mandelbrot example inside the repo?
I know it's not what you asked for
C
but maybe as a workaround it's useful
this code doesn't work:
class AThread(QtCore.QThread): def run(self): while True: if widget.isrun: print("thread ping") else: self.quit() time.sleep(1)
I
from main loop: thread = AThread() ... thread.quit() also doesn't work
yeah I know your bug report's code, I tried to quickly find a fix, but I couldn't it may be related to the CPython code generation
C
since I wrote the report of "where it happened"
C
I tried the quit too
then I tried to use quit()
but quit() also doesn't work in 5.14.1 and 5.13.2 (where terminate was working)
So I thought it doesn't related
I
So, if that's the same bug, ok
C
the error lies on how we handle the private implementation of QThread
I'm sorry I don't have a proper solution, but I shared your report with the other devs, so hopefully we can find the issue
I modified the internal GIL handlers of PySide to add an additional check
C
but now I need to verify that it's valid for all the user cases
print("isRunning: ", self.mythread.isRunning()) print( "isFinished: ", self.mythread.isFinished())
Ë
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_()
@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
I compared the output with PyQt5 and the value of both cases is the same
% python pyside-1282.py -> Running PyQt5 thread ping thread ping thread ping isrun = False isRunning: True isFinished: False % python pyside-1282.py -> Running PyQt5 thread ping thread ping thread ping thread stopped isRunning: True isFinished: False
C
Threading in these cases is quite difficult due to the 2 layers we have... Python land, and the Qt/C++ backend.
Yeah quit or terminate should work as expected after all.
Maybe I stumbled over this as well and thus never used it that way
Ë
for me waiting for the threads to finish just works 🤷‍♀️
after self.mythread.terminate()
I
it shows False and True
Ë
while widget.isrun: would do exactly the same
and for example...if I adda time.sleep(2) after it, I get "isRunning = False" and "isFinished = True"
thread ping thread ping thread ping thread stopped isRunning: False isFinished: True
the same happens to the isRun=False, I just need to "wait a bit" for the thread to be properly finished.
C
and it prints isRunning = False, and isFinished = True ;)
in fact the terminate() documentation says: " Use QThread::wait() after terminate(), to be sure."
C
which is similar to just do a time.sleep(x)
I
but inside qthread you know
Hopefully it's accepted as a solution by the dev team :P, if that's the case and we don't break any test, we can have this in 5.14.2.3 and 5.15.1
C
let's see how things evolve :)
Calendar: May 2020
Archive by month
Open in Telegram Каталог площадок Искать в ChatCrawler

A snapshot of an open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · What we do not do · Remove a page · Catalog