From 556bee45e1b4e31f1097d90099f2056f315d2e19 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 18 Sep 2023 11:22:02 -0600 Subject: [PATCH 1/2] Print the traceback. --- Modules/_xxsubinterpretersmodule.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index 700282efb8c619..33feae8ee82ff2 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -450,6 +450,10 @@ _run_script(PyInterpreterState *interp, const char *codestr, "RunFailedError: script raised an uncaught exception (%s)", failure); } + // XXX Instead, store the rendered traceback on sharedexc, + // attach it to the exception when applied, + // and teach PyErr_Display() to print it. + PyErr_Display(NULL, excval, NULL); Py_XDECREF(excval); if (errcode != ERR_ALREADY_RUNNING) { _PyInterpreterState_SetNotRunningMain(interp); From cdb517d5ee1d9355f5de39a3f5c9c42f2e07bbab Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 3 Oct 2023 18:06:08 -0600 Subject: [PATCH 2/2] Only print the traceback if there was an exception. --- Modules/_xxsubinterpretersmodule.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index 33feae8ee82ff2..bca16ac8a62eca 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -450,11 +450,13 @@ _run_script(PyInterpreterState *interp, const char *codestr, "RunFailedError: script raised an uncaught exception (%s)", failure); } - // XXX Instead, store the rendered traceback on sharedexc, - // attach it to the exception when applied, - // and teach PyErr_Display() to print it. - PyErr_Display(NULL, excval, NULL); - Py_XDECREF(excval); + if (excval != NULL) { + // XXX Instead, store the rendered traceback on sharedexc, + // attach it to the exception when applied, + // and teach PyErr_Display() to print it. + PyErr_Display(NULL, excval, NULL); + Py_DECREF(excval); + } if (errcode != ERR_ALREADY_RUNNING) { _PyInterpreterState_SetNotRunningMain(interp); }