You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
raise_single_exception_from_group causes SystemExit to have no exit status #3275
raise_single_exception_from_group was introduced as part of #3240 and #3197, but handles KeyboardInterrupt and SystemExit by wrapping the original exception in an exception of the same type:
# immediately bail out if there's any KI or SystemExitforeineg.exceptions:
ifisinstance(e, (KeyboardInterrupt, SystemExit)):
raisetype(e) fromeg
Notably, this causes the resulting SystemExit to have no exit status, so system.exit(1) (or really any other exit status) does not properly set the exit status. I do not see a good reason why the exception should not be raised directly:
# immediately bail out if there's any KI or SystemExitforeineg.exceptions:
ifisinstance(e, (KeyboardInterrupt, SystemExit)):
raiseefromeg
I assume to ensure trackbacks in the exception group remain alright. But we can probably do some handling cause this is only for SystemExit and KeyboardInterrupt.
yeah it's got special handling to bailout ASAP instead of doing special logic, but it should indeed preserve e.args. Feel free to contribute a PR, should be a simple one :)
# immediately bail out if there's any KI or SystemExitforeineg.exceptions:
ifisinstance(e, (KeyboardInterrupt, SystemExit)):
raisetype(e)(e.args) fromeg
Activity
A5rocks commentedon May 29, 2025
I assume to ensure trackbacks in the exception group remain alright. But we can probably do some handling cause this is only for SystemExit and KeyboardInterrupt.
cc @jakkdl
jakkdl commentedon May 30, 2025
yeah it's got special handling to bailout ASAP instead of doing special logic, but it should indeed preserve
e.args. Feel free to contribute a PR, should be a simple one :)seowalex commentedon May 31, 2025
Sure, I can do that. I presume my suggested solution above works?
CoolCat467 commentedon May 31, 2025
I don't see any reason immediately why it wouldn't work, no.
A5rocks commentedon May 31, 2025
raise e from egmight mutate the trace back ofeineg; just make sure it doesn't.jakkdl commentedon Jun 2, 2025
oh yeah, the helper is in large part specifically to avoid this problem. See python-trio/trio-websocket#191 or HypothesisWorks/hypothesis#4115.
I think the better fix is to do something like
seowalex commentedon Jun 6, 2025
I don't think
e.argsworks forSystemExit, but I will look at the issues and work something out.Fixes python-trio#3275; handle reraise of KI or SystemExit without lo…
Fixes #3275; handle reraise of KI or SystemExit without losing err co…