-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Turn signal.SIG* constants into enums #65275
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
Comments
Relevant discussion + BDFL approval: |
OK, somebody please review this (not me). |
This patch can't be reviewed: please re-generate without --git. |
This time I made it without --git but that didn't help either. Note: the devguide recommends using --git BTW: http://docs.python.org/devguide/committing.html |
OK, it appears it works now. Sorry for the notification noise. |
(replying here 'cause rietveld keeps giving me an exception when I submit a reply) On 2014/03/28 00:49:47, haypo wrote:
I guess it makes sense. |
New patch in attachment provides 3 enum containers and overrides all the necessary signal module APIs so that they interoperate with enums on both "get" and "set". |
Updated patch following Victor's suggestions is in attachment. |
If there are no other concerns I will commit latest patch tomorrow, then do the renaming. |
New changeset c9239171e429 by Giampaolo Rodola' in branch 'default': |
gcc -pthread -Xlinker -export-dynamic -o Modules/_testembed Modules/_testembed.o libpython3.5dm.a -lpthread -ldl -lutil -lm |
New changeset df5120efb86e by Victor Stinner in branch 'default': |
New changeset b1f5b5d7997f by Victor Stinner in branch 'default': |
Now signal.signal() accepts inappropriate types. >>> signal.signal(signal.SIGHUP, 0.0)
<Handlers.SIG_DFL: 0>
>>> signal.signal(signal.SIGHUP, '0')
<Handlers.SIG_DFL: 0> In 3.4 it raised an exception. |
And more: >>> import signal
>>> signal.signal(1.2, signal.SIG_DFL)
<Handlers.SIG_DFL: 0>
>>> signal.signal('1', signal.SIG_DFL)
<Handlers.SIG_DFL: 0> |
And more, as far as standard signal handler is tested for identity, signal.SIG_DFL and _signal.SIG_DFL should be the same object. Current code works only due to coincidence of two circumstances:
When small integer caching is disabled (NSMALLPOSINTS == NSMALLPOSINTS == 0) or when platform depended macros SIG_DFL and SIG_IGN are not small integers, the signal module will mystically fail. The simplest way to solve this issue is to backout turning SIG_DFL and SIG_IGN into enums. |
I know nothing about this part of CPython, but wouldn't the correct solution be to not compare by identity? |
I have other proposition -- turn them into functions (bpo-23325). |
Working on bpo-23673 I saw this in the new signal.py: +def _enum_to_int(value): The SIG, etc, constants are based on IntEnum, so they are already numeric values, and this function is unnecessary. |
Removing the 'enum_to_int' function would also take care of the accepting inappropriate types problem. |
Okay, in a perfect world that _enum_to_int function would be unnecessary, but as Serhiy pointed out the C code is doing pointer comparison, so unless the exact same int is passed in it does not work. I'm looking at adjusting the C code. |
signal constants are now enum, I close the issue. For further enhancements, please open a separated issue. $ python3
Python 3.8.3 (default, May 15 2020, 00:00:00)
>>> import signal; signal.SIGTERM
<Signals.SIGTERM: 15> |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: