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

Ensure tests do not leave signalhandlers #6667

Closed
Closed
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
24 changes: 24 additions & 0 deletions distributed/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2476,3 +2476,27 @@ def _bind_port(port):
raise TimeoutError(f"Default ports didn't open up in time for {name_of_test}")

yield


_default_signals = {sig: signal.getsignal(sig) for sig in signal.valid_signals()}

_allowed_overrides = {
signal.SIGSTOP, # pytest-timeout
}


def assert_default_signal_handlers():
assert _default_signals
for sig, default_handler in _default_signals.items():
if sig in _allowed_overrides:
continue
assert (
signal.getsignal(sig) is default_handler
), f"Non-default handler installed for signal {sig}: {signal.getsignal(sig)}"


@pytest.fixture(autouse=True)
def ensure_default_signalhandlers_active():
assert_default_signal_handlers()
yield
assert_default_signal_handlers()