Skip to content

Commit

Permalink
Restore log message about received signals in CLI (#6618)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjetter authored Jun 23, 2022
1 parent 4779f84 commit d9ab5cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions distributed/_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ async def wait_for_signals(signals: list[signal.Signals]) -> None:
event = asyncio.Event()

old_handlers: dict[int, Any] = {}
caught_signal: int | None = None

def handle_signal(signum, frame):
# *** Do not log or print anything in here
# https://stackoverflow.com/questions/45680378/how-to-explain-the-reentrant-runtimeerror-caused-by-printing-in-signal-handlers
nonlocal caught_signal
caught_signal = signum
# Restore old signal handler to allow for quicker exit
# if the user sends the signal again.
signal.signal(signum, old_handlers[signum])
Expand All @@ -28,6 +31,10 @@ def handle_signal(signum, frame):

try:
await event.wait()
assert caught_signal
logger.info(
"Received signal %s (%d)", signal.Signals(caught_signal).name, caught_signal
)
finally:
for sig in signals:
signal.signal(sig, old_handlers[sig])
1 change: 1 addition & 0 deletions distributed/cli/tests/test_dask_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ def test_signal_handling(loop, sig):
stdout, stderr = scheduler.communicate()
logs = stdout.decode().lower()
assert stderr is None
assert sig.name.lower() in logs
assert scheduler.returncode == 0
assert "scheduler closing" in logs
assert "end scheduler" in logs
1 change: 1 addition & 0 deletions distributed/cli/tests/test_dask_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ async def test_signal_handling(c, s, nanny, sig):
stdout, stderr = worker.communicate()
logs = stdout.decode().lower()
assert stderr is None
assert sig.name.lower() in logs
assert worker.returncode == 0
if nanny == "--nanny":
assert "closing nanny" in logs
Expand Down

0 comments on commit d9ab5cf

Please sign in to comment.