Check for errors in creating sub-interpreters when testing the C API.

This commit is contained in:
Brett Cannon 2012-02-03 12:08:03 -05:00
parent 61c4e10035
commit b6855683cc
1 changed files with 8 additions and 0 deletions

View File

@ -2396,6 +2396,14 @@ run_in_subinterp(PyObject *self, PyObject *args)
PyThreadState_Swap(NULL);
substate = Py_NewInterpreter();
if (substate == NULL) {
/* Since no new thread state was created, there is no exception to
propagate; raise a fresh one after swapping in the old thread
state. */
PyThreadState_Swap(mainstate);
PyErr_SetString(PyExc_RuntimeError, "sub-interpreter creation failed");
return NULL;
}
r = PyRun_SimpleString(code);
Py_EndInterpreter(substate);