-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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.strsignal(...) doesn't really return None if signal is not recognized #98930
Comments
On Windows, the signal module implements descriptions for the standard signals that are required by C --
I suggest the following:
|
I did the changes sir |
thanks! |
…honGH-99290) Improves the docstring on signal.strsignal to make it explain when it returns a message, None, or when it raises ValueError. Closes pythonGH-98930 Co-authored-by: Gregory P. Smith <greg@krypto.org>. (cherry picked from commit 88385b8) Co-authored-by: ram vikram singh <ramvikrams243@gmail.com>
Documentation
The documentation for signal.strsignal(...) says
Returns None if the signal is not recognized.
This a misleading way to describe what actually happens.Suggested better wording would be
Throws ValueError if signalnum is invalid, and returns None if there is no canonical name for signalnum for the platform.
From reading the implementation in cpython, this is my best understanding of what happens.
If the signal number is less than 1 or greater (or equal) to
signal.NSIG
(ie 65) a ValueError exception is thrown. (iesignal.strsignal(65)
throws aValueError
exception and does not returnNone
). This scenario is what I found most confusing about the documentation.If there is no suitable canonical name for the signal, then
signal.strsignal(..)
will returnNone
. For example on Linux, signal 32 doesn't have a canonical name. In that casesignal.strsignal(...)
does returnNone
. I am not an expert in Linux, but I did the following test, and it appears to me that signal 32 is pretty normal behaving signal, its usage is just deprecated and no longer has a standard name.It is pretty easy to verify that what I said about the cpython implementation is correct if HAVE_STRSIGNAL is true, however for HAVE_STRSIGNAL false, it depends a lot more on what
strsignal()
(from glibc) returns.From looking at the implementation in glibc glibc returns a string with a name of the signal or "Unknown signal". If glibc "Unknown signal" then cpython will return None.
The one caveat is that I am not fully clear how well my analysis carries over to the Windows platform. But at least for the Linux platform, I do feel that my suggested wording
Throws ValueError if signalnum is invalid, and returns None if there is no canonical name for signalnum for the platform.
is a good representation of what happens.The text was updated successfully, but these errors were encountered: