-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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 module always overwrites SIGINT on interpreter shutdown #74839
Comments
The signal module checks the SIGINT handler on startup. It only registers a new custom handler if the default OS handler is still installed, so that when embedding python in an application the SIGINT handler of that application is not overwritten. But on shutdown in finisignal, it *always* sets SIGINT to SIG_DFL. The reason is that it saves the old handler in old_siginthandler, but *only* if the signal handler is overwritten in init, which only happens when it was SIG_DFL in the first place! If there was already a handler in place in init (-> no overwriting), old_siginthandler will default to the initialization value, which is also SIG_DFL. This means that when an application embeds Python and needs a custom SIGINT handler, it will stop to work as soon as it shuts down Python since it will always be reset to SIG_DFL. |
I'd rather not backport this to 2.7 as it's quite late in the maintenance cycle and I'd like to avoid any regressions there. |
Since it's a subtle behavior change and the PR doesn't add a flag to opt-in for the old behaviour, I'm not sure about backporting the change (to 3.6 or 3.7). For 3.7, we are very close to the final release. It doesn't give much time to users to test the new behavior :-( I would suggest to keep the old behavior in Python 3.7 as well. To be honest, I don't understand well the change. So I'm not confortable with it. I understand that Py_Initialize() + Py_Finalize() restored the SIGINT handler, but now Python *always* sets SIGINT to SIG_DFL in Py_Finalize(). So if an application has its own signal handler, Python replaces it... But embedded Python also gives the choice of not setting Python signal handlers in Py_Initialize(). |
You have it backwards. Please read the bug report. |
That's a fair point. What's the procedure here? If I backport the fix to the 3.7 branch, will it go straight into the 3.7.0 release or will it be deferred to 3.7.1? @ned |
I'm confused by the NEWS entry: +Fixed reset of the SIGINT handler to SIG_DFL on interpreter shutdown even I read it as Python now always reset SIGINT to SIG_DFL. The commit title is more explicit: "Do not reset SIGINT (...)". I propose to rephrase the NEWS entry as: """ -- Ok, now I understood the change. In this case, I'm ok to backport it to 3.6 and 3.7. Python 2.7 has this behavior since 10 years, it seems like people learnt to live with it. I also dislike touching Python 2.7, to prevent any risk of regression if someone really rely on the current behavior. |
"All fixes that have been merged into the 3.7 branch as of cutoff tomorrow |
Ok, I think it go into 3.7.0 after all. 3.7.1 wouldn't get more testing before it's released anyway. |
Thanks pkerling for your bug report and your fix! |
Thanks! I'm a bit disappointed that it won't make it into 2.7, but I can understand the decision. To give some context: I came across this while working on Kodi and noticing that it does not shutdown cleanly via Ctrl+C or SIGTERM. After investigating, I came to the conclusion that it is due to this bug. Kodi shuts down the Python interpreter every time no add-on is doing active work, which is almost guaranteed to happen shortly after application startup. Then this bug caused a reset of the SIGTERM handler to the default handler, making the Kodi handler that does a clean shutdown useless. |
I'm nosy'ing Benjamin, the 2.7 release manager, in case he wants to comment on desirability of this bugfix in Python 2.7. |
It seems like this only affects embeddings and for embeddings, it's strictly an improvement? |
Short of any bug in the patch, yes, it's stricly an improvement. |
IMHO it's a bugfix. |
Reopening for the 2.7 backport discussion. |
So this is in 2.7 finally. Closing again. |
I marked bpo-24415 as duplicate of this issue. |
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: