Terry J. Reedy <tjre...@udel.edu> added the comment:
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. ---------- stage: -> needs patch type: -> behavior versions: +Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36958> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com