Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

@mvanhornmvanhorn commentedMar 10, 2026
edited by github-actionsbot
Loading

Fixes#145638

Summary

Addssignal.get_wakeup_fd() to return the current wakeup file descriptor without modifying it.

Currently, the only way to read the wakeup fd is viasignal.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.fd without any side effects.

Changes

  • Modules/signalmodule.c: Newsignal_get_wakeup_fd_impl function using Argument Clinic. Same main-thread check asset_wakeup_fd. Returnswakeup.fd directly.
  • 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.
  • 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 descriptorwithout modifying it. This avoids the race condition inherent in thecurrent workaround of calling set_wakeup_fd(-1) followed byset_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

Comment on lines +873 to +876
if (wakeup.fd != INVALID_FD)
return PyLong_FromSocket_t((SOCKET_T)wakeup.fd);
else
return PyLong_FromLong(-1);
Copy link
Member

@aiskaiskMar 10, 2026
edited
Loading

Choose a reason for hiding this comment

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

According toPEP7, braces should not omitted.

Suggested change
if (wakeup.fd!=INVALID_FD)
returnPyLong_FromSocket_t((SOCKET_T)wakeup.fd);
else
returnPyLong_FromLong(-1);
if (wakeup.fd!=INVALID_FD) {
returnPyLong_FromSocket_t((SOCKET_T)wakeup.fd);
}
else {
returnPyLong_FromLong(-1);
}

Copy link
Author

Choose a reason for hiding this comment

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

Thanks@aisk! Good catch — added braces per PEP 7 in908daa4.

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

Reviewers

@aiskaiskaisk left review comments

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Addsignal.get_wakeup_fd()

2 participants

@mvanhorn@aisk

[8]ページ先頭

©2009-2026 Movatter.jp