From 942ff16673c623ce2b9a86e84fab31cb99b62b65 Mon Sep 17 00:00:00 2001 From: Ken Date: Sat, 23 Jan 2021 19:23:25 +0800 Subject: [PATCH 1/4] Make IDLE respect sys.excepthook --- Lib/idlelib/run.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 1e84ecc6584ef..1d0cf5c8a178b 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -565,7 +565,10 @@ def runcode(self, code): self.usr_exc_info = sys.exc_info() if quitting: exit() - print_exception() + if sys.excepthook is sys.__excepthook__: + print_exception() + else: + sys.excepthook(*self.usr_exc_info) jit = self.rpchandler.console.getvar("<>") if jit: self.rpchandler.interp.open_remote_stack_viewer() From 4c891b5f33ef1866e43339369a7ab2abf3431812 Mon Sep 17 00:00:00 2001 From: Ken Date: Sat, 23 Jan 2021 23:58:01 +0800 Subject: [PATCH 2/4] Add blurb for IDLE fix --- .../NEWS.d/next/Library/2020-01-23-03-45-43.bpo-43008.lSZkGx.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-01-23-03-45-43.bpo-43008.lSZkGx.rst diff --git a/Misc/NEWS.d/next/Library/2020-01-23-03-45-43.bpo-43008.lSZkGx.rst b/Misc/NEWS.d/next/Library/2020-01-23-03-45-43.bpo-43008.lSZkGx.rst new file mode 100644 index 0000000000000..225b72d5878bc --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-01-23-03-45-43.bpo-43008.lSZkGx.rst @@ -0,0 +1 @@ +Fix: IDLE now correctly invokes :func:`sys.excepthook` in normal, 2-process mode. From 237be53df18700daf30635cb6b65c33a26f550e2 Mon Sep 17 00:00:00 2001 From: Ken Date: Sun, 24 Jan 2021 00:01:51 +0800 Subject: [PATCH 3/4] Update IDLE Restart Shell docs to say... ..." and reset display and exception handling". --- Doc/library/idle.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/idle.rst b/Doc/library/idle.rst index a59a5d3a46570..e7eaabd8bfa25 100644 --- a/Doc/library/idle.rst +++ b/Doc/library/idle.rst @@ -250,7 +250,7 @@ View Last Restart Scroll the shell window to the last Shell restart. Restart Shell - Restart the shell to clean the environment. + Restart the shell to clean the environment and reset display and exception handling. Previous History Cycle through earlier commands in history which match the current entry. From a11fa374e0f2818cf213d326901703f5fa8f107e Mon Sep 17 00:00:00 2001 From: Ken Date: Sun, 24 Jan 2021 00:06:57 +0800 Subject: [PATCH 4/4] IDLE: Handle sys.excepthook errors... ...when raising in 2-process mode, in a way that matches normal shell behavior. --- Lib/idlelib/run.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 1d0cf5c8a178b..c7610bce4b7f4 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -568,7 +568,13 @@ def runcode(self, code): if sys.excepthook is sys.__excepthook__: print_exception() else: - sys.excepthook(*self.usr_exc_info) + try: + sys.excepthook(*self.usr_exc_info) + except: + 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() jit = self.rpchandler.console.getvar("<>") if jit: self.rpchandler.interp.open_remote_stack_viewer()