Commit 411ada27 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Python errors need to be flushed explcitly.

When vtkPVPythonInformation was calling Python code to tests modules, it
wasn't flushing the Python errors, if any. Fixes that.
parent ed22b446
......@@ -100,12 +100,21 @@ void vtkPVPythonInformation::DeepCopy(vtkPVPythonInformation* info)
#ifdef PARAVIEW_ENABLE_PYTHON
namespace
{
void flushAndClearErrors()
{
if (PyErr_Occurred())
{
PyErr_Print(); // print implies PyErr_Clear().
}
}
bool hasModule(const char* module)
{
vtkPythonScopeGilEnsurer gilEnsurer;
vtkSmartPyObject mod(PyImport_ImportModule(module));
bool result = mod;
return result;
flushAndClearErrors();
return mod;
}
// Returns empty string on error.
......@@ -113,6 +122,7 @@ std::string getModuleAttrAsString(const char* module, const char* attribute)
{
vtkPythonScopeGilEnsurer gilEnsurer;
vtkSmartPyObject mod(PyImport_ImportModule(module));
flushAndClearErrors();
if (!mod)
{
std::ostringstream result;
......@@ -121,6 +131,7 @@ std::string getModuleAttrAsString(const char* module, const char* attribute)
}
vtkSmartPyObject attr(PyObject_GetAttrString(mod, attribute));
flushAndClearErrors();
if (!attr)
{
std::ostringstream result;
......
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