Skip to content

Commit 07b4f30

Browse files
marcowidmerdanieldegrasse
authored andcommitted
pytest twister harness: increase timeout when stopping subprocess
When running pytest tests with coverage enabled, the test process starts to write the coverage data when it receives the SIGTERM signal. On slow machines, this can take longer than 0.5s. Increase the timeout and only attempt to kill the process if it is still running after the timeout. Signed-off-by: Marco Widmer <marco.widmer@bytesatwork.ch>
1 parent 957ef08 commit 07b4f30

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _stop_subprocess(self) -> None:
8181
return
8282
return_code: int | None = self._process.poll()
8383
if return_code is None:
84-
terminate_process(self._process)
84+
terminate_process(self._process, self.base_timeout)
8585
return_code = self._process.wait(self.base_timeout)
8686
self._process = None
8787
logger.debug('Running subprocess finished with return code %s', return_code)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import shlex
1212
import signal
1313
import subprocess
14-
import time
1514

1615
import psutil
1716

@@ -38,7 +37,7 @@ def log_command(logger: logging.Logger, msg: str, args: list, level: int = loggi
3837
logger.log(level, msg, shlex.join(args))
3938

4039

41-
def terminate_process(proc: subprocess.Popen) -> None:
40+
def terminate_process(proc: subprocess.Popen, timeout: float = 0.5) -> None:
4241
"""
4342
Try to terminate provided process and all its subprocesses recursively.
4443
"""
@@ -47,6 +46,7 @@ def terminate_process(proc: subprocess.Popen) -> None:
4746
with contextlib.suppress(ProcessLookupError, psutil.NoSuchProcess):
4847
os.kill(child.pid, signal.SIGTERM)
4948
proc.terminate()
50-
# sleep for a while before attempting to kill
51-
time.sleep(0.5)
52-
proc.kill()
49+
try:
50+
proc.wait(timeout=timeout)
51+
except subprocess.TimeoutExpired:
52+
proc.kill()

0 commit comments

Comments
 (0)