[PyQt] QThread terminate trouble when porting to Python 3

Phil Thompson phil at riverbankcomputing.com
Mon Sep 24 12:49:54 BST 2012


On Sat, 22 Sep 2012 22:25:24 +0430, Lee Harr <missive at hotmail.com> wrote:
> 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())

For me it fails in the same way with Python 2.7 and 3.3. I don't see this
as a bug in either Python, Qt or PyQt.

Phil


More information about the PyQt mailing list