From cb28ae769e790cb7cba39cbb17d0ce11ced10d91 Mon Sep 17 00:00:00 2001 From: Sebastian Cao Date: Tue, 16 Jun 2026 16:47:05 +0800 Subject: [PATCH] Propagate sigint_timeout/sigkill_timeout to the final process.stop() on exit --- tests/test_run_process.py | 23 ++++++++++++++++++++++- watchfiles/run.py | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/test_run_process.py b/tests/test_run_process.py index 91638198..2fbb610b 100644 --- a/tests/test_run_process.py +++ b/tests/test_run_process.py @@ -10,7 +10,15 @@ from watchfiles import arun_process, run_process from watchfiles.main import Change -from watchfiles.run import detect_target_type, import_string, run_function, set_tty, split_cmd, start_process +from watchfiles.run import ( + CombinedProcess, + detect_target_type, + import_string, + run_function, + set_tty, + split_cmd, + start_process, +) if TYPE_CHECKING: from conftest import MockRustType @@ -113,6 +121,19 @@ def test_sigint_timeout(mocker, mock_rust_notify: 'MockRustType', caplog): assert "SIGINT timed out after 'sigint_timeout' seconds" in caplog.text +def test_sigint_timeout_propagates_to_final_stop(mocker, mock_rust_notify: 'MockRustType'): + mocker.patch('watchfiles.run.spawn_context.Process', return_value=FakeProcess()) + mocker.patch('watchfiles.run.os.kill') + stop_spy = mocker.spy(CombinedProcess, 'stop') + mock_rust_notify([{(1, '/path/to/foobar.py')}]) + + assert run_process('/x/y/z', target=object(), debounce=5, step=1, sigint_timeout=7, sigkill_timeout=8) == 1 + # both the in-loop stop and the final stop in the finally block should use the custom timeouts + assert stop_spy.call_count == 2 + for call in stop_spy.call_args_list: + assert call.kwargs == {'sigint_timeout': 7, 'sigkill_timeout': 8} + + def test_start_process(mocker): mock_process = mocker.patch('watchfiles.run.spawn_context.Process') v = object() diff --git a/watchfiles/run.py b/watchfiles/run.py index 86366185..e0a61494 100644 --- a/watchfiles/run.py +++ b/watchfiles/run.py @@ -151,7 +151,7 @@ def foobar(a, b, c): process = start_process(target, target_type, args, kwargs, changes) reloads += 1 finally: - process.stop() + process.stop(sigint_timeout=sigint_timeout, sigkill_timeout=sigkill_timeout) return reloads