Some people have been experiencing some problems with the Python interpreter in VTK and ParaView, when initializing their own Python interpreter and using ParaView Python capability as well.

A new CMake variable has been added to ParaView, VTK_PYTHON_FULL_THREADSAFE, which will turn on the GIL Ensure/Release on all VTK and ParaView Python calls.

If you are developing for VTK and ParaView, make sure to use the vtkPythonScopeGilEnsurer before any Python call. It is a noop without the CMmake option, but will automatically call PyGILState_Ensure() and PyGILState_Release() on the scope of the variable if defined.

In vtkPythonInterpreter.cxx e.g. :

    // Redirect Python's stdout and stderr and stdin - GIL protected operation
    {   
    vtkPythonScopeGilEnsurer gilEnsurer;
    PySys_SetObject(const_cast<char*>("stdout"),
      reinterpret_cast<PyObject*>(wrapperOut));
    PySys_SetObject(const_cast<char*>("stderr"),
      reinterpret_cast<PyObject*>(wrapperErr));
    PySys_SetObject(const_cast<char*>("stdin"),
      reinterpret_cast<PyObject*>(wrapperOut));
    Py_DECREF(wrapperOut);
    Py_DECREF(wrapperErr);
    }   

 

 

Leave a Reply