exceptiongroup icon indicating copy to clipboard operation
exceptiongroup copied to clipboard

handle SystemExit exceptions in excepthook

Open njsmith opened this issue 6 years ago • 1 comments
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.

njsmith avatar Jan 29 '19 09:01 njsmith

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)

njsmith avatar Jan 29 '19 09:01 njsmith