Browse Source

squelch backtrace on SystemExit

David Rose 14 years ago
parent
commit
646f12f625

+ 3 - 0
direct/src/task/Task.py

@@ -502,6 +502,9 @@ class TaskManager:
                         self.step()
                 except KeyboardInterrupt:
                     self.stop()
+                except SystemExit:
+                    self.stop()
+                    raise
                 except IOError, ioError:
                     code, message = self._unpackIOError(ioError)
                     # Since upgrading to Python 2.4.1, pausing the execution

+ 2 - 0
dtool/src/pystub/pystub.cxx

@@ -147,6 +147,7 @@ extern "C" {
   EXPCL_DTOOLCONFIG extern void *PyExc_RuntimeError;
   EXPCL_DTOOLCONFIG extern void *PyExc_StandardError;
   EXPCL_DTOOLCONFIG extern void *PyExc_StopIteration;
+  EXPCL_DTOOLCONFIG extern void *PyExc_SystemExit;
   EXPCL_DTOOLCONFIG extern void *PyExc_TypeError;
   EXPCL_DTOOLCONFIG extern void *PyExc_ValueError;
   EXPCL_DTOOLCONFIG extern void *_Py_NoneStruct;
@@ -290,6 +291,7 @@ void *PyExc_IndexError = (void *)NULL;
 void *PyExc_RuntimeError = (void *)NULL;
 void *PyExc_StandardError = (void *)NULL;
 void *PyExc_StopIteration = (void *)NULL;
+void *PyExc_SystemExit = (void *)NULL;
 void *PyExc_TypeError = (void *)NULL;
 void *PyExc_ValueError = (void *)NULL;
 void *_Py_NoneStruct = (void *)NULL;

+ 11 - 2
panda/src/event/pythonTask.cxx

@@ -420,8 +420,17 @@ do_python_task() {
   }
 
   if (result == (PyObject *)NULL) {
-    task_cat.error()
-      << "Exception occurred in " << *this << "\n";
+    if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) {
+      // Don't print an error message for SystemExit.  Or rather, make
+      // it a debug message.
+      if (task_cat.is_debug()) {
+        task_cat.debug()
+          << "SystemExit occurred in " << *this << "\n";
+      }
+    } else {
+      task_cat.error()
+        << "Exception occurred in " << *this << "\n";
+    }
     return DS_interrupt;
   }
 

+ 18 - 12
panda/src/pipeline/thread.cxx

@@ -309,18 +309,24 @@ call_python_func(PyObject *function, PyObject *args) {
     result = PyObject_Call(function, args, NULL);
 
     if (result == (PyObject *)NULL) {
-      // Temporarily save and restore the exception state so we can print a
-      // callback on-the-spot.
-      PyObject *exc, *val, *tb;
-      PyErr_Fetch(&exc, &val, &tb);
-      
-      Py_XINCREF(exc);
-      Py_XINCREF(val);
-      Py_XINCREF(tb);
-      PyErr_Restore(exc, val, tb);
-      PyErr_Print();
-      
-      PyErr_Restore(exc, val, tb);
+      if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) {
+        // If we caught SystemExit, let it pass by without bothering
+        // to print a callback.
+
+      } else {
+        // Temporarily save and restore the exception state so we can
+        // print a callback on-the-spot.
+        PyObject *exc, *val, *tb;
+        PyErr_Fetch(&exc, &val, &tb);
+        
+        Py_XINCREF(exc);
+        Py_XINCREF(val);
+        Py_XINCREF(tb);
+        PyErr_Restore(exc, val, tb);
+        PyErr_Print();
+        
+        PyErr_Restore(exc, val, tb);
+      }
     }
 
   } else {