Terry J. Reedy <tjre...@udel.edu> added the comment:
I looked at all 4 hooks. sys.breakpointhook is invoked by breakpoint() in user code, so is not IDLE's concern at present. sys.unraiseablehook is invoked by the interpreter when user code messes up badly, so is not IDLE's condern. (And it is an expert feature that beginners should ignore.) sys.displayhook is set to rpc.displayhook in run.py or, if started with -n no subprocess, pyshell.py. IDLE executes user code with exec(). Shell entries are compiled in 'single' mode. Exec invokes displayhook for expression statements so compiled. In both normal and -n mode, displayhook exceptions are displayed and processed as user code exceptions, with the last traceback line giving the bad line. sys.excepthook is invoked by the interpreter for uncaught exceptions. In IDLE's -n mode, sys.excepthook *is* invoked. If it raises, both tracebacks are printed, separated by "\nDuring handling of the above exception, another exception occurred:\n". This issue is about having the same effect in normal 2-process mode. Since, in the subprocess, IDLE catches all user exceptions for its custom handling, there are no uncaught user exceptions. I believe your patch calls the user hook in the proper place, but an uncaught exception in sys.excepthook would be nasty. Replace the call with something like try: sys.e...k(...) except BaseException as e: print_exception() print("\nDuring handling of the above exception, another exception occurred:\n", file=sys.stderr) self.usr_exc_info = sys.exc_info() print_exception() If possible, I want a unittest added in test_run.py. (I am not sure exactly how as I don't think we have yet directly faked receipt of compiled user code.) class Executive(unittest.TextCase): def test_good_excepthook(self): def test_bad_excepthook(self): A blurb is needed (and always is for anything non-trivial). In Doc/library/idle.rst, I want to insert " and reset display and exception handling" before the period ending the current Shell entry. Restart Shell Restart the shell to clean the environment. ---------- stage: -> test needed title: IDLE ignores sys.excepthook -> IDLE ignores sys.excepthook in normal, subprocess mode versions: -Python 3.6, Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43008> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com