Skip to content

Commit 133e127

Browse files
M1chakartben
authored andcommitted
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: 0df8240 Signed-off-by: Michael Zimmermann <[email protected]>
1 parent a9b76dc commit 133e127

File tree

1 file changed

+2
-3
lines changed
  • scripts/pylib/pytest-twister-harness/src/twister_harness/device

1 file changed

+2
-3
lines changed

scripts/pylib/pytest-twister-harness/src/twister_harness/device/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from __future__ import annotations
66

7+
import contextlib
78
import logging
89
import os
910
import platform
@@ -42,10 +43,8 @@ def terminate_process(proc: subprocess.Popen) -> None:
4243
Try to terminate provided process and all its subprocesses recursively.
4344
"""
4445
for child in psutil.Process(proc.pid).children(recursive=True):
45-
try:
46+
with contextlib.suppress(ProcessLookupError, psutil.NoSuchProcess):
4647
os.kill(child.pid, signal.SIGTERM)
47-
except (ProcessLookupError, psutil.NoSuchProcess):
48-
pass
4948
proc.terminate()
5049
# sleep for a while before attempting to kill
5150
time.sleep(0.5)

0 commit comments

Comments
 (0)