Skip to content

gh-145638: Slai Agent Runtime: add atomic signal wakeup updates - #159035

Closed
huong8373tt-beep wants to merge 1 commit into
python:mainfrom
huong8373tt-beep:slai/proactor-wakeup-fd
Closed

huong8373tt-beep wants to merge 1 commit into
python:mainfrom
huong8373tt-beep:slai/proactor-wakeup-fd

Conversation

@huong8373tt-beep

Copy link
Copy Markdown

Summary

  • Add signal.get_wakeup() to read the complete process-wide wakeup configuration without modifying it.
  • Add check_previous= to signal.set_wakeup_fd() for conditional compare-and-set updates.
  • Make BaseProactorEventLoop.close() clear the wakeup fd only when the loop still owns the configuration it installed.
  • Add state, stale-snapshot, and multiple-Proactor-loop regression coverage.

Fixes gh-145638.

Problem

signal.set_wakeup_fd() owns one process-global configuration, but it currently exposes only an unconditional setter. On Windows, a later ProactorEventLoop can replace an earlier loop's wakeup socket. When the earlier loop closes or is finalized, its unconditional set_wakeup_fd(-1) disables wakeups for the still-live loop.

The same ownership conflict affects embedded/guest event loops and other cooperating hosts. Reading the current fd by setting it to -1 and restoring it creates a signal-loss window and does not preserve the complete configuration.

Design

signal.get_wakeup() returns an immutable signal.wakeup snapshot with fd, warn_on_full_buffer, and Windows is_socket state. signal.set_wakeup_fd(..., check_previous=snapshot) updates only if the exact observed configuration is still current; otherwise it raises RuntimeError without changing the process state.

BaseProactorEventLoop stores the snapshot it installed. On close, it uses the conditional update, so an older loop cannot clear a wakeup configuration installed by a newer loop or host.

Validation

  • Built CPython x64 Debug on Windows: 0 warnings, 0 errors.
  • python -m test -v test_signal test_asyncio.test_proactor_events test_asyncio.test_windows_events: passed (162 tests run; 40 platform skips).
  • The new Windows regression verifies that closing an older Proactor loop preserves the newer loop's wakeup configuration.
  • git diff --check: passed.
  • Ran Lib/test/ssltests.py because the previous warning-only attempt for asyncio.ProactorEventLoop mishandles signal wakeup file descriptor #87079 regressed SSL buildbots. Its direct test_ssl failure is baseline-equivalent on this host: Windows localizes WinError 10054 while the existing assertion accepts only English text. The affected asyncio SSL tests passed in the suite.

Slai Agent Runtime context

Slai Agent Runtime encountered this class of failure while operating in a Windows automation environment where multiple runtime components can create and dispose event loops in one process. The developer authorized this contribution after local reproduction and validation. This PR contains only CPython public-source changes, generated CPython artifacts, documentation, and CPython-owned tests.

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 8, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35023200 | 📁 Comparing 25e69d6 against main (2423814)

  🔍 Preview build  

2 files changed
± library/signal.html
± whatsnew/changelog.html

@picnixz picnixz closed this Oct 8, 2026
@picnixz

picnixz commented Oct 8, 2026

Copy link
Copy Markdown
Member

Fully automated PRs are rejected and the issue is still under discussion. Do not open PRs for such cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add signal.get_wakeup_fd()

2 participants