pipeline: Don't exit process when SystemExit happens on external thread

PyErr_Print() causes the process to be forcibly exited when a SystemExit exception occurred, this is a big issue on Android.
This commit is contained in:
rdb 2021-12-10 13:54:58 +01:00
parent 25d57e0eef
commit cc865e6d21

View File

@ -245,16 +245,22 @@ call_python_func(PyObject *function, PyObject *args) {
PyObject *exc, *val, *tb;
PyErr_Fetch(&exc, &val, &tb);
thread_cat.error()
<< "Exception occurred within " << *current_thread << "\n";
// Temporarily restore the exception state so we can print a callback
// on-the-spot.
Py_XINCREF(exc);
Py_XINCREF(val);
Py_XINCREF(tb);
PyErr_Restore(exc, val, tb);
PyErr_Print();
// on-the-spot, except if it's a SystemExit, which would cause PyErr_Print
// to exit the process immediately.
if (exc != PyExc_SystemExit) {
thread_cat.error()
<< "Exception occurred within " << *current_thread << "\n";
Py_XINCREF(exc);
Py_XINCREF(val);
Py_XINCREF(tb);
PyErr_Restore(exc, val, tb);
PyErr_Print();
} else {
thread_cat.info()
<< "SystemExit occurred within " << *current_thread << "\n";
}
PyGILState_Release(gstate);