Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore signal handlers after wait for signals is done #6400

Merged
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
6 changes: 5 additions & 1 deletion distributed/_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ def handle_signal(signum, frame):
for sig in signals:
old_handlers[sig] = signal.signal(sig, handle_signal)

await event.wait()
try:
await event.wait()
finally:
for sig in signals:
signal.signal(sig, old_handlers[sig])
19 changes: 18 additions & 1 deletion distributed/cli/tests/test_dask_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def test_version_option():


@pytest.mark.slow
def test_idle_timeout(loop):
def test_idle_timeout():
start = time()
runner = CliRunner()
result = runner.invoke(
Expand All @@ -424,6 +424,23 @@ def test_idle_timeout(loop):
assert result.exit_code == 0


@pytest.mark.slow
def test_restores_signal_handler():
# another test could have altered the signal handler, so use a new function
# that both has sensible sigint behaviour *and* can be used as a sentinel
def raise_ki():
raise KeyboardInterrupt

original_handler = signal.signal(signal.SIGINT, raise_ki)
try:
CliRunner().invoke(
distributed.cli.dask_scheduler.main, ["--idle-timeout", "1s"]
)
assert signal.getsignal(signal.SIGINT) is raise_ki
finally:
signal.signal(signal.SIGINT, original_handler)


def test_multiple_workers_2(loop):
text = """
def dask_setup(worker):
Expand Down