[PyQt] isRunning() returns true after QThread completion
lars.beiderbecke at googlemail.com
Sun Feb 26 14:55:25 GMT 2012
In my application some QThreads still return isRunning() == true when
they should be completed.
More specifically, I'm using QThreads to load images asynchronously in
the background. By emitting a signal, the thread notifies the main
window that the pixmap has been loaded and the corresponding widget
can be updated (code has been simplified):
# ... load image ...
self.requests = set()
def request(self, filename):
t = ImgRequest(self, filename)
self.connect(t, QtCore.SIGNAL("sigDone"), self.ack)
def ack(self, t):
# ... update image ...
print "WARNING: thread still running"
When I run above code, however, I'll often get WARNING messages, i.e.,
QThread.isRunning() is returning true even though its corresponding
run() method has been completed.
Is this merely a race condition between the signal and the actual
completion of run(), or am I missing something fundamental about
QThreads? Do I really need isRunning() and wait()? And finally, is
there a better way to deal with the QThread objects than storing them
in a set so that the GC won't kill them while running?
More information about the PyQt