twister: terminate_process: use contextlib.suppress
While it doesn't cause any issues, it's more consistent and makes future
commits which add handling for more exception types more readable.
Based on: 0df8240b49
Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
This commit is contained in:
parent
a9b76dcb1b
commit
133e1278c2
1 changed files with 2 additions and 3 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
|
@ -42,10 +43,8 @@ def terminate_process(proc: subprocess.Popen) -> None:
|
|||
Try to terminate provided process and all its subprocesses recursively.
|
||||
"""
|
||||
for child in psutil.Process(proc.pid).children(recursive=True):
|
||||
try:
|
||||
with contextlib.suppress(ProcessLookupError, psutil.NoSuchProcess):
|
||||
os.kill(child.pid, signal.SIGTERM)
|
||||
except (ProcessLookupError, psutil.NoSuchProcess):
|
||||
pass
|
||||
proc.terminate()
|
||||
# sleep for a while before attempting to kill
|
||||
time.sleep(0.5)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue