[PyQt] QThread not exiting

Kerri Reno kreno at yumaed.org
Fri Oct 19 18:07:34 BST 2007


OK, I took out all the GUI elements, but I still can't get the QThread to
exit:

from PyQt4 import QtGui, QtCore
import time, sys

class BusyThread(QtCore.QThread):

    def __init__(self,parent):
        QtCore.QThread.__init__(self,parent)
        self.exiting = False
        self.run()

    def run(self):
        print 'got here'

        while not self.exiting:
            print 'inc'
            self.sleep(1)
        return

    def destroy(self):
        self.exiting = True
        self.wait()

class Menu(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        self.show()

        t = BusyThread(self)

        time.sleep(5)
        t.destroy()

def main(args):
    app = QtGui.QApplication(args)
    mainWindow = Menu()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main(sys.argv)


TIA, Kerri

On 10/19/07, Andreas Pakulat <apaku at gmx.de> wrote:
>
> On 19.10.07 09:25:05, Kerri Reno wrote:
> > I'm trying to run a progress bar in a QThread, while other stuff runs in
> the
> > main thread.  I can't get the QThread to exit.  It just goes on
> forever.  My
> > code is attached - please help!
>
> You can't. GUI elements can not work outside the main thread. If you
> have things that need a separate thread send signals from the threads
> run() method or post events which then get captured by the gui elements
> (either via a slot or a customEvent() function) and then can update the
> gui apropriately.
>
> Also if you access variables in your thread class from multiple threads
> you want to protect them against concurrent access, for example by using
> QMutexLocker with a QMutex.
>
> Andreas
>
> --
> Advancement in position.
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



-- 
Yuma Educational Computer Consortium
Compass Development Team
Kerri Reno
kreno at yumaed.org      (928) 502-4240
.·:*¨¨*:·.   .·:*¨¨*:·.   .·:*¨¨*:·.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20071019/c7439f43/attachment.html


More information about the PyQt mailing list