Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion tests/test_run_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion watchfiles/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Loading