QThread.terminate in Python 3

L

Lee Harr

Hi;

I have asked this on the PyQt list, but have not seen any
response yet. Hoping someone will be able to test this
on their system to see if they see the same problem.

The problem I am seeing is that terminating a QThread running
certain code will freeze the program, requiring it to be kill'd.

Adding a sleep will allow the QThread to be terminated, but
for my use I need to be able to terminate any arbitrary code.
I understand that use of QThread.terminate is discouraged,
but it has worked well previously and I would like to continue
this use if possible.

I see the problem on Python 3.2.3 with PyQt 4.9.1 on Ubuntu 12.4

With Python 2.7.3 with PyQt 4.9.1 there is no problem.

I am hoping to find out if this is a bug, and if so, where
I should report it (Python, PyQt, Qt, Linux, etc).

Thanks for any pointers.



Here is a program that shows the problem:


# 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())
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top