Commit 7c8572e0 authored by Mathieu Westphal's avatar Mathieu Westphal

Adding a NoRelease Option to GilEnsrurer and use it

Some python calls take care of realeasing gil (eg. Py_Finalize), some when using gilEnsurer before this call, it is needed to only Ensure gil without releasing when going out of scope, has it has already been released. If not python will output a warning.
So a noRelease parameter have been added to gilEnsurer and this parameter have been used where it was necessary.
parent f04cf077
......@@ -139,7 +139,7 @@ they are system headers. Do NOT add any #undef lines here. */
class vtkPythonScopeGilEnsurer
{
public:
vtkPythonScopeGilEnsurer(bool force = false)
vtkPythonScopeGilEnsurer(bool force = false, bool noRelease = false)
: State(PyGILState_UNLOCKED)
{
#ifdef VTK_PYTHON_FULL_THREADSAFE
......@@ -147,6 +147,7 @@ public:
force = true;
#endif
this->Force = force;
this->NoRelease = noRelease;
if (this->Force)
{
this->State = PyGILState_Ensure();
......@@ -154,7 +155,7 @@ public:
}
~vtkPythonScopeGilEnsurer()
{
if (this->Force)
if (this->Force && !this->NoRelease)
{
PyGILState_Release(this->State);
}
......@@ -163,6 +164,7 @@ public:
private:
PyGILState_STATE State;
bool Force;
bool NoRelease;
vtkPythonScopeGilEnsurer(const vtkPythonScopeGilEnsurer&); // Not implemented.
void operator=(const vtkPythonScopeGilEnsurer&); // Not implemented.
......
......@@ -197,6 +197,7 @@ void vtkPythonInterpreter::Finalize()
if (Py_IsInitialized() != 0)
{
NotifyInterpreters(vtkCommand::ExitEvent);
vtkPythonScopeGilEnsurer gilEnsurer(false, true);
Py_Finalize();
}
}
......@@ -331,7 +332,7 @@ int vtkPythonInterpreter::PyMain(int argc, char** argv)
return res;
#else
vtkPythonScopeGilEnsurer gilEnsurer;
vtkPythonScopeGilEnsurer gilEnsurer( false, true);
return Py_Main(argc, argv);
#endif
}
......
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