Commit dc80e76b authored by David C. Lonie's avatar David C. Lonie
Browse files

Don't print MPL exceptions to stdout.

This causes a lot of paraview tests to fail when "ImportError" appears
in the output.

Change-Id: I60cd29cf959302d5d7d98b46bc82eb8781072cd7
parent dc8fb555
...@@ -222,9 +222,33 @@ vtkMatplotlibMathTextUtilities* vtkMatplotlibMathTextUtilities::New() ...@@ -222,9 +222,33 @@ vtkMatplotlibMathTextUtilities* vtkMatplotlibMathTextUtilities::New()
!PyImport_ImportModule("matplotlib") || !PyImport_ImportModule("matplotlib") ||
PyErr_Occurred()) PyErr_Occurred())
{ {
vtkMplStartUpDebugMacro("Error occurred. Writing exception info to " // Fetch the exception info. Note that value and traceback may still be
"stdout/stderr."); // NULL after the call to PyErr_Fetch().
PyErr_PrintEx(0); PyObject *type = NULL;
PyObject *value = NULL;
PyObject *traceback = NULL;
PyErr_Fetch(&type, &value, &traceback);
SmartPyObject typeStr(PyObject_Str(type));
SmartPyObject valueStr(PyObject_Str(value));
SmartPyObject tracebackStr(PyObject_Str(traceback));
vtkMplStartUpDebugMacro(
"Error during matplotlib import:\n"
<< "\nStack:\n"
<< (tracebackStr.GetPointer() == NULL
? "(none)"
: const_cast<char*>(
PyString_AsString(tracebackStr.GetPointer())))
<< "\nValue:\n"
<< (valueStr.GetPointer() == NULL
? "(none)"
: const_cast<char*>(
PyString_AsString(valueStr.GetPointer())))
<< "\nType:\n"
<< (typeStr.GetPointer() == NULL
? "(none)"
: const_cast<char*>(
PyString_AsString(typeStr.GetPointer()))));
PyErr_Clear();
vtkMatplotlibMathTextUtilities::MPLMathTextAvailable = UNAVAILABLE; vtkMatplotlibMathTextUtilities::MPLMathTextAvailable = UNAVAILABLE;
return NULL; return NULL;
} }
...@@ -345,11 +369,35 @@ bool vtkMatplotlibMathTextUtilities::CheckForError() ...@@ -345,11 +369,35 @@ bool vtkMatplotlibMathTextUtilities::CheckForError()
PyObject *exception = PyErr_Occurred(); PyObject *exception = PyErr_Occurred();
if (exception) if (exception)
{ {
vtkDebugMacro(<< "Python exception raised.");
if (this->Debug) if (this->Debug)
{ {
PyErr_PrintEx(0); // Fetch the exception info. Note that value and traceback may still be
// NULL after the call to PyErr_Fetch().
PyObject *type = NULL;
PyObject *value = NULL;
PyObject *traceback = NULL;
PyErr_Fetch(&type, &value, &traceback);
SmartPyObject typeStr(PyObject_Str(type));
SmartPyObject valueStr(PyObject_Str(value));
SmartPyObject tracebackStr(PyObject_Str(traceback));
vtkWarningMacro(<< "Python exception raised:\n"
<< "\nStack:\n"
<< (tracebackStr.GetPointer() == NULL
? "(none)"
: const_cast<char*>(
PyString_AsString(tracebackStr.GetPointer())))
<< "\nValue:\n"
<< (valueStr.GetPointer() == NULL
? "(none)"
: const_cast<char*>(
PyString_AsString(valueStr.GetPointer())))
<< "\nType:\n"
<< (typeStr.GetPointer() == NULL
? "(none)"
: const_cast<char*>(
PyString_AsString(typeStr.GetPointer()))));
} }
PyErr_Clear();
return true; return true;
} }
return false; return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment