fix: catch TimeoutExpired in parallel runner wait loop
The initial wait loop used proc.wait(timeout=0.5) which could raise subprocess.TimeoutExpired and crash the runner. Added a try/except and increased timeout to 5s so the runner polls correctly without crashing. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent
d65b2190e2
commit
78c9b635e9
@@ -106,7 +106,10 @@ def cli(pairs: tuple[str, ...]) -> None:
|
||||
if not finished_indices:
|
||||
# No process finished yet, wait a bit
|
||||
for proc in processes:
|
||||
proc.wait(timeout=0.5)
|
||||
try:
|
||||
proc.wait(timeout=5)
|
||||
except subprocess.TimeoutExpired:
|
||||
pass
|
||||
continue
|
||||
|
||||
# Remove finished processes from the list
|
||||
|
||||
@@ -147,6 +147,40 @@ class TestCli:
|
||||
assert result.exit_code == 1
|
||||
assert "FAILURE" in result.output
|
||||
|
||||
def test_wait_loop_handles_timeout(self, tmp_path: Path) -> None:
|
||||
from click.testing import CliRunner
|
||||
|
||||
with (
|
||||
patch("scripts.run_molecule_parallel.run_pair") as mock_run_pair,
|
||||
patch("os.killpg") as mock_killpg,
|
||||
patch("os.getpgid") as mock_getpgid,
|
||||
):
|
||||
mock_getpgid.return_value = 123
|
||||
|
||||
good_proc = MagicMock()
|
||||
good_proc.poll.return_value = None
|
||||
good_proc.wait.side_effect = [
|
||||
subprocess.TimeoutExpired("cmd", 5),
|
||||
None,
|
||||
None,
|
||||
]
|
||||
bad_proc = MagicMock()
|
||||
bad_proc.poll.side_effect = [None, 1, 1, 1]
|
||||
bad_proc.wait.return_value = None
|
||||
mock_run_pair.side_effect = [bad_proc, good_proc]
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
cli,
|
||||
[
|
||||
"default|ubuntu-2204|img:latest|",
|
||||
"lifecycle|debian-12|img:deb|",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 1
|
||||
assert "FAILURE" in result.output
|
||||
mock_killpg.assert_called()
|
||||
|
||||
|
||||
def test_main_module_block() -> None:
|
||||
import scripts.run_molecule_parallel as rm
|
||||
|
||||
Reference in New Issue
Block a user