-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kill the entire subtree when killing child process #143
Conversation
I've seen this behavior a couple of times on Windows, usually it's because the process group is not setup correctly or the process was spawned in such a way that breaks the connection between parent and child. I have not seen this behavior on Linux however though it could be possible for grandchild processes. All that said, could you please make a couple of modifications? I'm thinking something like this: @classmethod
def _signal_process(signal, parent, children):
assert signal in ("KILL", "TERM")
method = signal.lower()
if signal == "TERM":
method = "terminate"
if parent.is_running():
getattr(parent, method)() # needs a try: except Exception block
for child in children:
getattr(parent, method)() # needs a try: except Exception block
def kill(self):
process = self.psutil_process
children = process.children(recursive=True)
self.process.signalProcess("KILL")
reactor.callLater(2, self._signal_process, parent, children) # '2' should be configurable |
8978171
to
9b6817e
Compare
Is this better now? This still has problems, namely the process killed this way will return a return code of zero, signalling successful execution. In my test case (with Maya), this is not that much of a problem, because we are already parsing the process's output to know when a frame was finished, but it's still weird. The best solution would probably involve setting up a correct process group when running on Windows, but I have no idea how to do that... |
On Windows, killing a process will by default not kill that process's child processes as well. This can be a problem when we're trying to stop an assignment.
This gives kill() and terminate() a chance to do the right thing.
9b6817e
to
7cf75c9
Compare
Yes thank you, merge when ready.
I've done this before using pywin32 so I'll be happy to add it. Opening up #147 to work on this at a later time since for now the solution you have here is probably enough in the short term. |
Kill the entire subtree when killing child process
On Windows, killing a process will by default not kill that process's
child processes as well. This can be a problem when we're trying to stop
an assignment.