문제

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?

도움이 되었습니까?

해결책 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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top