QThread.terminate in Python 3

Discussion in 'Python' started by Lee Harr, Sep 23, 2012.

  1. Lee Harr

    Lee Harr Guest

    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())
     
    Lee Harr, Sep 23, 2012
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pradnyesh Sawant

    problem with qthread and signal/slot

    Pradnyesh Sawant, Apr 14, 2007, in forum: Python
    Replies:
    0
    Views:
    481
    Pradnyesh Sawant
    Apr 14, 2007
  2. daved170

    PyQT Qthread stuck main app

    daved170, Sep 15, 2009, in forum: Python
    Replies:
    0
    Views:
    443
    daved170
    Sep 15, 2009
  3. Dennis Lee Bieber

    Re: QThread.terminate in Python 3

    Dennis Lee Bieber, Sep 23, 2012, in forum: Python
    Replies:
    0
    Views:
    208
    Dennis Lee Bieber
    Sep 23, 2012
  4. Lee Harr

    Re: QThread.terminate in Python 3

    Lee Harr, Sep 29, 2012, in forum: Python
    Replies:
    0
    Views:
    204
    Lee Harr
    Sep 29, 2012
  5. Dennis Lee Bieber

    Re: QThread.terminate in Python 3

    Dennis Lee Bieber, Sep 29, 2012, in forum: Python
    Replies:
    0
    Views:
    267
    Dennis Lee Bieber
    Sep 29, 2012
Loading...

Share This Page