New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IDLE should print exit message or status if one is provided #81139
Comments
IDLE currently just returns to the interactive prompt when a script exits, even if SystemExit has arguments. This can be confusing to new users if they are using sys.exit to print a message. |
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 bpo-18196, a follow-up of comments in bpo-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 bpo-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. |
Thanks for the report. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: