squelch backtrace on SystemExit

This commit is contained in:
David Rose 2012-02-16 00:19:09 +00:00
parent 0b0a286101
commit 646f12f625
4 changed files with 34 additions and 14 deletions

View File

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

View File

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

View File

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

View File

@ -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 {