Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt application closes successfully, but process is not killed?

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?

like image 585
thecreator232 Avatar asked Dec 26 '22 12:12

thecreator232


2 Answers

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)
like image 186
thecreator232 Avatar answered Dec 31 '22 13:12

thecreator232


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.

like image 36
ekhumoro Avatar answered Dec 31 '22 13:12

ekhumoro