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. Advertisements

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. Ernesto

    Self terminate a python program

    Ernesto, Nov 15, 2005, in forum: Python
    Replies:
    1
    Views:
    7,074
    Ben Finney
    Nov 15, 2005
  2. Sullivan WxPyQtKinter

    To my clients force to terminate a python CGI program?

    Sullivan WxPyQtKinter, Mar 28, 2006, in forum: Python
    Replies:
    0
    Views:
    417
    Sullivan WxPyQtKinter
    Mar 28, 2006
  3. Pradnyesh Sawant

    problem with qthread and signal/slot

    Pradnyesh Sawant, Apr 14, 2007, in forum: Python
    Replies:
    0
    Views:
    551
    Pradnyesh Sawant
    Apr 14, 2007
  4. Gros Bedo
    Replies:
    2
    Views:
    1,596
    Piet van Oostrum
    Jul 10, 2008
  5. daved170

    PyQT Qthread stuck main app

    daved170, Sep 15, 2009, in forum: Python
    Replies:
    0
    Views:
    513
    daved170
    Sep 15, 2009
  6. David Boddie

    Re: PyQT Qthread stuck main app

    David Boddie, Sep 15, 2009, in forum: Python
    Replies:
    2
    Views:
    525
    Dave Angel
    Sep 15, 2009
  7. someone
    Replies:
    0
    Views:
    855
    someone
    Nov 21, 2009
  8. Jonathan Lee

    Re: Pass View object to QThread

    Jonathan Lee, Jan 3, 2010, in forum: C++
    Replies:
    3
    Views:
    1,122
    Rui Maciel
    Jan 3, 2010
Loading...