[PyQt] QThread not forcibly terminating as expected
apaku at gmx.de
Tue Mar 6 07:54:09 GMT 2012
On 05.03.12 13:35:02, Brian Knudson wrote:
> On Mar 3, 2012, at 4:00 AM, pyqt-request at riverbankcomputing.com wrote:
> > Message: 1
> > Date: Sat, 3 Mar 2012 10:17:39 +0100
> > From: Andreas Pakulat <apaku at gmx.de>
> > To: pyqt at riverbankcomputing.com
> > Subject: Re: [PyQt] QThread not forcibly terminating as expected
> > Message-ID: <20120303091739.GA8274 at trinity.apaku.dnsalias.org>
> > Content-Type: text/plain; charset=us-ascii
> > Can you show some sample code for this, I don't quite understand what
> > you mean with "its not updatable" or "its locked"?
> As is often the case, while making my example, I found the solution to one of my problems... I'm using only one thread for this widget, so while it's busy, the widget can't be updated. Using multiple threads will fix this - to a degree. Please read on.
Ah, so with the example you provided there would've been only 1 qthread
object and you re-used it? Thats indeed not a good idea, each thread
should run only once, so you should create a new object each time you
want to run something in a thread.
> > Can you leave out the network-system from your app, replace it with some
> > kind of busy-loop, i.e.
> > while(True):
> > time.sleep(.5)
> > Does that still lock up the widget until you terminate the thread? If so
> > please post a minimal example.
> I've made a small example: http://churchofbk.com/misc/qthread_example.py.
> In this example, I've replicated the way I'm doing things in my application so it may not be the ideal way of doing things for this small of an example, but it works. My question is still related to the fact that threads don't seem to stop executing when I tell them to.
The reason that the thread is not terminating in the code above is that
you're using self.quit(). If you look in the API docs, you'll notice
that quit merely ends the event-loop of the QThread. But in your example
you never start the event-loop in the threads, so there's nothing to
quit. Changing that to use self.terminate() makes the example code work
as expected, the label is not updated for PushButton 2.
If thats not the case for you your Qt and PyQt versions might be
interesting, maybe its a bug in either that got fixed.
More information about the PyQt