Browse Source

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.
rdb 4 years ago
parent
commit
cc865e6d21
1 changed files with 15 additions and 9 deletions
  1. 15 9
      panda/src/pipeline/pythonThread.cxx

+ 15 - 9
panda/src/pipeline/pythonThread.cxx

@@ -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);