Skip to content

fix: a shutdown signal on the signal-module fallback wakes an idle loop - #106

Merged
AlexeyShalaev merged 1 commit into
masterfrom
fix/signal-fallback-wakes-loop
Nov 9, 2026
Merged

AlexeyShalaev merged 1 commit into
masterfrom
fix/signal-fallback-wakes-loop

Conversation

@AlexeyShalaev

Copy link
Copy Markdown
Member

Summary

When the loop can't register signal handlers (add_signal_handler raises), install_signal_handlers falls back to signal.signal. That handler set the stop event directly. A signal.signal handler runs outside the loop's callbacks, so setting the event only queues its waiters: an idle loop slept until its selector timed out, or forever with no timer pending.

The fallback now schedules the stop with call_soon_threadsafe, which wakes the loop, as the Windows handler already did. Both paths share one handler, and a second signal still exits at once without going through the loop.

The new test sends SIGTERM to the main thread while the loop waits on the event under a 3 s wait_for. Before the fix the wait ended at 3.0 s, by the timer; now it ends right after the signal.

Type of change

  • Bug fix

Checklist

  • Tests added or updated
  • make check passes locally (ruff + mypy)
  • CHANGELOG.md left alone
  • Documentation updated (if the public API changed): no public API change

Unit: 801 passed, 14 skipped, coverage 92.5%. Integration: 9 passed.

When the loop can't register signal handlers, the fallback handler set the stop event straight from signal.signal. That only queues the event's waiters, so an idle loop slept until its selector timed out, or forever with no timer pending. It now schedules the stop through call_soon_threadsafe, as the Windows handler already did, and both paths share one handler.
@AlexeyShalaev
AlexeyShalaev merged commit f507ab1 into master Nov 9, 2026
7 checks passed
@AlexeyShalaev
AlexeyShalaev deleted the fix/signal-fallback-wakes-loop branch November 9, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant