last day (15 days later) » 

9:02 AM
0
Q: Ignore or silence QThread warning

DjentI have an application in python that uses PySide for the GUI. To keep the application responsive, I have a lot of threading. Some of the threads are daemon threads that are meant to work forever, some are also daemon threads that we don't care if they finish. Application works fine, the respon...

 
add thread = None before def main(): and add global app before thread = Thread()
 
That's not my question. I want to ignore the warning. In my real application there is a class that maintains the reference to the QT app, and all references to threads are removed. I just want to ignore this warning from QT without non-zero exit code.
 
So your goal is that the message: QThread: Destroyed while thread is still running is not visible on the console?
 
I don't really care about the message. More on the non-zero exit code.
 
The duplicate that I have proposed is according to the code that you have proposed so complaining doesn't work, you better spend your time improving your minimal reproducible example
 
9:02 AM
But my code works perfectly fine. The problem is only when application is being closed. The Python reference to thread is removed, but the QT thread is still running. This is causing the message.
 
Although the door is the exit of my house is also part of it, so if the door is wrong my house is also bad. The same happens for your application, so in conclusion your program is also bad even if only in that small part.
 
I disagree that the question is duplicate, the problem I have is different
and as I said - the problem is with daemon threads that are still running in the background
some of them are meant to never finish, some of them may finish but I don't know when if ever
so removing Python reference will not help in this case, since the issue is with underlying QT threads
 
QThread is handled differently than threading, in my case I never inherit QThread but use the worker (QObject) approach that lives in a thread. If you are forced to inherit from QThread then make the following changes:
1) change while True: to while not self.isInterruptionRequested():
2) To stop the QThread use: thread.requestInterruption() thread.quit() thread.wait()
 
yeah, that's the problem
that I can't do that
some of my threads are not running in the loop
 
9:17 AM
mmm I do not understand you
 
so there is no flag
I have a long running taks, that should not block GUI
and it is running in a thread
but there is no loop, just a lot of work
but nothing bad will happen if user decides to quit application before the task finishes
 
If you do not use a loop I recommend focusing on the worker(QObject) -QThread approach
 
I tried this approach before, but it doesn't change anything
 
if the worker still is running, the effect will be the same
if you dereference it in python, there still will be the QT part running
 
9:20 AM
mmm, it seems to me that you have not implemented it correctly, you can show a MWE of how you use the new approach
 
ok, I'll try that again, give me a moment
 
In my case I do not need to stop it because when the application finishes running the same Qt removes it without problems
I recommend that you try my examples and you will see that it does not generate the problem you indicate
1
A: Checking file permissions in a QThread, with Retry/Cancel dialog box (in the GUI thread)

eyllanescFrom the experience that I have the approach to subclassify QThread is not good for these cases. A simple solution is to use the worker(QThread)-thread approach since the worker can have several tasks such as doing the heavy calculation and saving the file. So the GUI could launch the first tas...

 
9:41 AM
hmm, I think I'm doing something wrong with the worker approach, since it never returns control
ok, I have changed self.worker.process() to QtCore.QTimer().singleShot(0, self.worker.process), but it prevents app from being closed.
 
Why don't you use threading.Thread()? with that it doesn't generate that problem anymore
 
the QT is not thread safe
I cannot use regular threading
to be honest I did that, and I got a lot of segfaults
and now I'm switching to QT threads
 

last day (15 days later) »