-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Treat KeyboardInterrupt
or SystemExit
the same on program exit even if they are inside exception groups
#130713
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
cc @iritkatriel as one of exception groups' PEP author |
I think we would need a new PEP for this, and I'm not sure it's worth it. Basically any change to a builtin requires a PEP, because other Python implementations are following the standard (which is, in this case, what PEP-654 specifies), not what we arbitrarily think is correct on our end. See #129867 (comment). |
To be clear this is a change in running a script -- no change in (I think you misunderstood the issue) |
Ah, thanks for clarifying--I was interpreting this as changing the way But, I'm still not quite sure if it's right to special-case these for the return codes. This would still create some deviation between CPython and other implementations, right? (If PEP-654 didn't specify any special case for how these should get handled, then one could argue that it was implicitly specified that they should behave the same.) |
There is already deviation -- on Windows, pypy exits with exit code 2 not
EDIT: previously I accidentally compared pypy's Python 2 with CPython's Python 3. EDIT 2: after learning that this behavior was added sometime after Python 3, I found that KeyboardInterrupt's handling was added in #41078 in 2019. |
I don't think this needs a pep, contextlib.supress was changed without one, and the behaviour of setting the exit code was also added without a pep |
|
Just again as a clarification, this would modify
s.t. This is not proposing changing:
|
Ok, I thought that it would also warrant a change in the how we represent the base exception groups. Anyway built-ins usually refer to primitive types (such as int, str, exceptions, etc) but also other stuff that I am not aware of. OTOH, a PEP is usually needed when the change is either breaking enough and/or is big and changes the language. To make And then, without considering which code is to be affected, the fact that the specs (the PEP) did not explicitly explain how to handle such exceptions upon exit may still warrant a new PEP. Or as @ZeroIntensity said, "then one could argue that it was implicitly specified that they should behave the same", in which case, we should treat this as a bug fix. But I don't know whether it's better to be implicit or explicit. |
Yeah, that's what I'm concerned about. A return code is technically part of the API--it's used in tests and in CI to check if something failed. This might be niche enough that we don't have to worry about it, but for now, I'm inclined to point this to DPO first. |
I'll do that and edit a link in -- should the pending tag be removed? |
Uh oh!
There was an error while loading. Please reload this page.
Feature or enhancement
Proposal:
A
KeyboardInterrupt
orSystemExit
inside aBaseExceptionGroup
should be treated like a bareKeyboardInterrupt
orSystemExit
.Looking at the CPython source code, I believe
_Py_HandleSystemExitAndKeyboardInterrupt
is the relevant function.Points for it:
Points against:
SystemExit
in an exception group prints out the stack trace, unlike when it's not in an exception groupSystemExit
and print the exception group then)I volunteer to implement this if this is fine.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
EDIT: I have now made a post. See https://discuss.python.org/t/keyboardinterrupt-and-systemexit-in-exception-groups-should-be-considered-for-pythons-exit-code/82816
Links to previous discussion of this feature:
I have tried some basic keyword searches as well as some digging in blame, but I can't find any previous discussion.
The text was updated successfully, but these errors were encountered: