Question

i just noticed that when i run a pyqt application and close it, the application closes , but the process is still alive. Apparently the process that was running does not close even after closing the application.

Traceback (most recent call last):
  File "F:\Projects\XYZ\XYZ\XYZ.py", line 414, in <module>
    sys.exit(app.exec_())
SystemExit: 0

When i searched online , its says that if the return value is 0 , it is a normal termination. As you see the process keep on pilling up as i run the application.

enter image description here

So how do i overcome this problem?

Was it helpful?

Solution 2

This looks like a problem specific to IDLE.

There are several issues on the python bug tracker that are closely related (e.g. 8093 and 12540), but they are now closed and resolved as "fixed".

Since it appears that you are using a very old version of python (2.5), you should be able to solve the problem by upgrading.

OTHER TIPS

SOLUTION

This a quick fix , that i was able to make to solve this problem.

import psutil, os

def kill_proc_tree(pid, including_parent=True):    
    parent = psutil.Process(pid)
    for child in parent.children(recursive=True):
        child.kill()
    if including_parent:
        parent.kill()


app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow() # <-- Instantiate QMainWindow object.
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
app.exec_()


me = os.getpid()
kill_proc_tree(me)

Have you tried the following?

sys.exit(app.exec_)

It's common practice among PyQt developers, and an easy way to cleanly quit your program. You should, however, upgrade to Python 2.7 or Python 3.3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top