Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29820 > unrolled thread

QThread.terminate in Python 3

Started byLee Harr <missive@hotmail.com>
First post2012-09-23 20:39 +0430
Last post2012-09-23 20:39 +0430
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  QThread.terminate in Python 3 Lee Harr <missive@hotmail.com> - 2012-09-23 20:39 +0430

#29820 — QThread.terminate in Python 3

FromLee Harr <missive@hotmail.com>
Date2012-09-23 20:39 +0430
SubjectQThread.terminate in Python 3
Message-ID<mailman.1123.1348416619.27098.python-list@python.org>
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())

 		 	   		  

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web