twister: terminate_process: fix NoSuchProcess error
NOTE: Even though previous commits indicate, that this can only happen on MacOS, that's actually not true. It happens on Linux as well. The constructor of `psutil.Process` can throw an exception as well, so we need to wrap the whole loop in another try, unfortunately. Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
This commit is contained in:
parent
133e1278c2
commit
76b24fac09
2 changed files with 8 additions and 6 deletions
|
@ -42,6 +42,7 @@ def terminate_process(proc: subprocess.Popen) -> None:
|
|||
"""
|
||||
Try to terminate provided process and all its subprocesses recursively.
|
||||
"""
|
||||
with contextlib.suppress(ProcessLookupError, psutil.NoSuchProcess):
|
||||
for child in psutil.Process(proc.pid).children(recursive=True):
|
||||
with contextlib.suppress(ProcessLookupError, psutil.NoSuchProcess):
|
||||
os.kill(child.pid, signal.SIGTERM)
|
||||
|
|
|
@ -59,6 +59,7 @@ def terminate_process(proc):
|
|||
so we need to use try_kill_process_by_pid.
|
||||
"""
|
||||
|
||||
with contextlib.suppress(ProcessLookupError, psutil.NoSuchProcess):
|
||||
for child in psutil.Process(proc.pid).children(recursive=True):
|
||||
with contextlib.suppress(ProcessLookupError, psutil.NoSuchProcess):
|
||||
os.kill(child.pid, signal.SIGTERM)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue