Message342823
https://docs.python.org/3/library/exceptions.html#SystemExit says: skip traceback, convert default None to 0, print any other non-int and convert to 1, and pass unprinted int to C exit().
I agree that IDLE should also print non-ints. The IDLE doc should mention its non-exit behavior.
[https://docs.python.org/3/library/sys.html#sys.exit adds more about int return codes and that exit() only exits the process in the main thread. Neither is relevant here.]
I believe the relevant code is the following, from run.Executive.runcode:
except SystemExit:
# Scripts that raise SystemExit should just
# return to the interactive prompt
pass
except:
self.usr_exc_info = sys.exc_info()
if quitting:
exit()
# even print a user code SystemExit exception, continue
print_exception()
jit = self.rpchandler.console.getvar("<<toggle-jit-stack-viewer>>")
if jit:
self.rpchandler.interp.open_remote_stack_viewer()
The bare except clause, including the comment, is from 2003. The 'except SystemExit' clause was added 2013 June 11 in #18196, a follow-up of comments in #5492. The obsoleted comment should have been deleted. The behavior suppressed was always printing traceback + message. What should have been retained was printing non-int messages, but I don't think that either Roger or I were aware of that behavior.
One could argue that SystemExit in user code should trigger an exit from the user execution process, which would trigger a Shell Restart. This would be closer to the standard behavior. But it does not hurt, and may be better, to keep the process and let the user trigger a restart when wanted. In the case that inspired #18196, the SystemExit came from site.py, not user code, and definitely should not cause a restart.
I will try something like the following:
except SystemExit as e:
ob = e.args[0]
if not isinstance(ob, (type(None), int)):
print('SystemExit: ' + str(ob), file=sys.stderr)
Since the message will be followed by a normal prompt rather than an exit, I want to 'enhance' the message with the prefix and error color. |
|
Date |
User |
Action |
Args |
2019-05-18 23:09:19 | terry.reedy | set | recipients:
+ terry.reedy, Random832 |
2019-05-18 23:09:19 | terry.reedy | set | messageid: <1558220959.82.0.793159221956.issue36958@roundup.psfhosted.org> |
2019-05-18 23:09:19 | terry.reedy | link | issue36958 messages |
2019-05-18 23:09:18 | terry.reedy | create | |
|