This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients AbyxDev, terry.reedy
Date 2021-01-23.14:31:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1611412317.45.0.148820379474.issue43008@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-01-23 14:31:57terry.reedysetrecipients: + terry.reedy, AbyxDev
2021-01-23 14:31:57terry.reedysetmessageid: <1611412317.45.0.148820379474.issue43008@roundup.psfhosted.org>
2021-01-23 14:31:57terry.reedylinkissue43008 messages
2021-01-23 14:31:57terry.reedycreate