X Tutup
Skip to content

gh-145638: Add signal.get_wakeup_fd()#145726

Open
mvanhorn wants to merge 2 commits intopython:mainfrom
mvanhorn:osc/145638-add-get-wakeup-fd
Open

gh-145638: Add signal.get_wakeup_fd()#145726
mvanhorn wants to merge 2 commits intopython:mainfrom
mvanhorn:osc/145638-add-get-wakeup-fd

Conversation

@mvanhorn
Copy link
Contributor

@mvanhorn mvanhorn commented Mar 10, 2026

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 by signal.set_wakeup_fd(fd), which creates a race condition window where signals can be lost. The new function simply reads wakeup.fd without any side effects.

Changes

  • Modules/signalmodule.c: New signal_get_wakeup_fd_impl function using Argument Clinic. Same main-thread check as set_wakeup_fd. Returns wakeup.fd directly.
  • Doc/library/signal.rst: Documentation for the new function.
  • Lib/test/test_signal.py: Tests verifying get_wakeup_fd() returns -1 when unset, the correct fd after set_wakeup_fd(), and -1 again after clearing.
  • NEWS entry added.

Test plan

  • test_get_wakeup_fd added covering set/get/clear cycle
  • NEWS entry added
  • Argument Clinic directives used

This contribution was developed with AI assistance (Claude Code).


📚 Documentation preview 📚: https://cpython-previews--145726.org.readthedocs.build/

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>
attempting to call it from other threads will cause a :exc:`ValueError`
exception to be raised.

.. versionadded:: 3.15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. versionadded:: 3.15
.. versionadded:: next

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add signal.get_wakeup_fd()

2 participants

X Tutup