[PyQt] QThread terminate trouble when porting to Python 3

Lee Harr missive at hotmail.com
Sat Sep 22 18:55:24 BST 2012


I created a simple test case to demonstrate the problem I am having.

As it is, running in Python 3.2 with PyQt 4.9.1 on Ubuntu, the program
freezes when trying to terminate the QThread.

With the sleep, or if running on Python 2.7 with PyQt 4.9.1 the
thread will terminate and the main thread will exit normally.

(To run with Python 2, switch to Python 2 print statement. Also
works successfully with print as a function in Python 2.)

Can this be considered a bug? In what? Python, PyQt or Qt? Or
does this fall under the "do not attempt to terminate a QThread"
warning?

Thanks for any help.


# test_qthread.py

#from __future__ import print_function

import time
from PyQt4 import QtCore


class CmdThread(QtCore.QThread):
    def run(self):
        while True:
            #print 'test'
            print('test')
            #time.sleep(0.2)


if __name__ == '__main__':
    t = CmdThread()
    print('thread set up')
    t.start()
    print('thread started')
    time.sleep(1)
    print('terminating thread')
    t.terminate()
    print('terminated')
    time.sleep(1)
    print('thread is running:', t.isRunning())

 		 	   		  


More information about the PyQt mailing list