Do not fail if process already ended

We can expect the subprocess has already ended by the time we're
checking for child processes. Handle this case gracefully so that tests
do not fail with an exception.
This commit is contained in:
Daniel A. Wozniak 2018-10-24 10:17:59 -07:00
parent 85e22d2f25
commit 7f613ac020
No known key found for this signature in database
GPG Key ID: 166B9D2C06C82D61

View File

@ -1548,7 +1548,11 @@ def win32_kill_process_tree(pid, sig=signal.SIGTERM, include_parent=True,
''' '''
if pid == os.getpid(): if pid == os.getpid():
raise RuntimeError("I refuse to kill myself") raise RuntimeError("I refuse to kill myself")
try:
parent = psutil.Process(pid) parent = psutil.Process(pid)
except psutil.NoSuchProcess:
log.debug("PID not found alive: %d", pid)
return ([], [])
children = parent.children(recursive=True) children = parent.children(recursive=True)
if include_parent: if include_parent:
children.append(parent) children.append(parent)