gh-145638: Add signal.get_wakeup_fd()#145726
Open
mvanhorn wants to merge 2 commits intopython:mainfrom
Open
Conversation
Add signal.get_wakeup_fd() to return the current wakeup file descriptor without modifying it. This avoids the race condition inherent in the current workaround of calling set_wakeup_fd(-1) followed by set_wakeup_fd(fd) to read the current value. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
aisk
reviewed
Mar 10, 2026
| attempting to call it from other threads will cause a :exc:`ValueError` | ||
| exception to be raised. | ||
|
|
||
| .. versionadded:: 3.15 |
Member
There was a problem hiding this comment.
Suggested change
| .. versionadded:: 3.15 | |
| .. versionadded:: next |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #145638
Summary
Adds
signal.get_wakeup_fd()to return the current wakeup file descriptor without modifying it.Currently, the only way to read the wakeup fd is via
signal.set_wakeup_fd(-1)followed bysignal.set_wakeup_fd(fd), which creates a race condition window where signals can be lost. The new function simply readswakeup.fdwithout any side effects.Changes
Modules/signalmodule.c: Newsignal_get_wakeup_fd_implfunction using Argument Clinic. Same main-thread check asset_wakeup_fd. Returnswakeup.fddirectly.Doc/library/signal.rst: Documentation for the new function.Lib/test/test_signal.py: Tests verifyingget_wakeup_fd()returns -1 when unset, the correct fd afterset_wakeup_fd(), and -1 again after clearing.Test plan
test_get_wakeup_fdadded covering set/get/clear cycleThis contribution was developed with AI assistance (Claude Code).
signal.get_wakeup_fd()#145638📚 Documentation preview 📚: https://cpython-previews--145726.org.readthedocs.build/