-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
signal.set_wakeup_fd
does not work unless you register a no-op signal handler for the relevant signal
#131803
Comments
It's a documentation issue :-) You should register a signal handler in Python to use set_wakeup_fd(), unless Python already has set up a signal handler for the signal. |
Thanks! I'll send in a PR updating the docs. Python's standard library usually seems more friendly than this. @vstinner what do you think about this suggestion from above?
This function already does other forms of validation (checking if we're in the main thread and checking if the FD is non blocking). I do understand that that could be considered a breaking change, I don't know what CPython's attitude to this sort of footgun-removal is. |
Could you elaborate on what's suggested here? Note there's often at least one signal handler installed already: the runtime installs one for |
Wow, I'm sorry for the noise here. Of course it couldn't know that. Please ignore my comments above. I'll send in a docs PR! |
Bug report
Bug description:
Consider this program that uses
signal.signal.set_wakeup_fd
:demo.py
:If I run this with
REGISTER_SIGNAL_HANDLER=1
, it works:However, if I run this without registering the signal handler, it hangs indefinitely:
All the real world usages I've been able to find of
signal.set_wakeup_fd
register a no-op signal handler for the signal(s) they're interested in. For example, see this CPython test:cpython/Lib/test/test_signal.py
Line 340 in 8a00c9a
I don't know if we would consider this is a bug in the implementation or a bug in the documentation, but IMO, it's a pretty confusing experience for people who don't know this. Some ideas:
signal.set_wakeup_fd
to register a no-op signal handler for you if there isn't a corresponding signal handler already registered.signal.set_wakeup_fd
to error out if there is no signal handler already registered.I'd be happy to implement some of these ideas if folks tell me what seems best!
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: