Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,16 @@ def test_failure(self):
with self.assertRaises(ExecutionFailed):
interp.exec('raise Exception')

def test_failure_with_broken_exception_str(self):
interp = interpreters.create()
with self.assertRaises(interpreters.InterpreterError):
interp.exec(dedent("""
class BrokenError(Exception):
def __str__(self):
raise ValueError
raise BrokenError
"""))

@force_not_colorized
def test_display_preserved_exception(self):
tempdir = self.temp_dir()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash in :meth:`concurrent.interpreters.Interpreter.exec` when the
uncaught exception's ``__str__`` raises.
8 changes: 8 additions & 0 deletions Python/crossinterp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2018,6 +2018,14 @@ _PyXI_ApplyError(_PyXI_error *error, const char *failure)
PyThreadState *tstate = PyThreadState_Get();

if (failure != NULL) {
if (error->override != NULL
&& error->override->code == _PyXI_ERR_NO_MEMORY)
{
PyErr_NoMemory();
}
else {
PyErr_SetString(PyExc_InterpreterError, failure);
}
xi_error_clear(error);
return NULL;
}
Expand Down
Loading