exceptiongroup
exceptiongroup copied to clipboard
handle SystemExit exceptions in excepthook
trafficstars
The old MultiError code didn't have to worry about this, because of unwrapping, but we do. If a program terminates with an ExceptionGroup that consists of only SystemExit exceptions, then it should terminate silently.
Oh, and we have to handle the argument correctly, which can either be an integer exit code, or a string to print. This might be tricky for multiple SystemExits in the same group... Which is probably fine, that's a weird edge case anyway, we just have to decide what to do with it. The main thing is that this should work as expected:
async def get_outta_here():
sys.exit(...)
async def main():
async with trio.open_nursery() as nursery:
nursery.start_soon(get_outta_here)
trio.run(main)