0

I am running Python3 on OSX; so far I have been using console apps launched by terminal), and from my understanding, the terminal is spawning process and they are child of the spawner, so when that goes away, all the child process are terminated.

Although, now I am running UI; tried with TKinter and then moved on PyQt5. In this case, I am experiencing some problems where my test process is not closed as it happen in the terminal, but hang as zombie. While I believe that the zombie process is not much of a problem, what concern me is that I do not have control or understanding of "who is running the boat", as far as process ownership.

Is there a way to get a sort of tree, about which process is holding on another process(or multiple ones); so I can handle the order and close the right ones? Also for some reason, even giving a sudo kill -9 on the zombie process does not kill it; so I would really like to know what is happening in the backend and handle things correctly.

1 Answers1

0

PyQt is a Python binding for the actual Qt C code, when you start a PyQt app you are starting the Python process and the C Qt loop process.

You have zombie processes left because when you terminate your python process you don't necessarily terminate the C process.

Here is the thing, In PyQt when a Qt Object is deleted, it deletes all other Qt Ojbects that are related to it (childs, subchilds, etc), but if there was one that had no parent or which was somehow left unreachable, it will become a zombie process and you will have no way of killing it unless you reset your computer or you find and kill the Qt loop.

So to make your life easier, you should set your code to have 1 main object and all other objects should be related to it, so when you terminate your app all you need to do is delete one object and all other object's will be correctly deleted.

in a simple app you would just have something like this:

app = QApplication(sys.argv)
main = MainObject()
main.show()
sys.exit(app.exec_())

The exit is handled by sys.exit(app.exec_()) and all your app objects inherit from main.

But if you want to delete a Qt object during execution you cant just delete it as you normally would in python. You must let Qt handle the deletion by setting it to be deleted:

object.deleteLater()

You can get a better explanation of this in this answer by ekhumoro

  • Well, this is OK, until you try to make multiple calls to multiple modules in Python, and your QT frontend is still running. The concept that an application is using just one process is not always true. For example I can open my QT C loop with the UI, run Python code and have it complete and exit; so the calling module once done is de-allocated; but if you call a Popen for example, and start a different executable; that will not quit, even if the main Python object that called it, is destroyed and de-allocated. –  Jan 29 '18 at 21:29