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. */ ...@@ -139,7 +139,7 @@ they are system headers. Do NOT add any #undef lines here. */
class vtkPythonScopeGilEnsurer class vtkPythonScopeGilEnsurer
{ {
public: public:
vtkPythonScopeGilEnsurer(bool force = false) vtkPythonScopeGilEnsurer(bool force = false, bool noRelease = false)
: State(PyGILState_UNLOCKED) : State(PyGILState_UNLOCKED)
{ {
#ifdef VTK_PYTHON_FULL_THREADSAFE #ifdef VTK_PYTHON_FULL_THREADSAFE
...@@ -147,6 +147,7 @@ public: ...@@ -147,6 +147,7 @@ public:
force = true; force = true;
#endif #endif
this->Force = force; this->Force = force;
this->NoRelease = noRelease;
if (this->Force) if (this->Force)
{ {
this->State = PyGILState_Ensure(); this->State = PyGILState_Ensure();
...@@ -154,7 +155,7 @@ public: ...@@ -154,7 +155,7 @@ public:
} }
~vtkPythonScopeGilEnsurer() ~vtkPythonScopeGilEnsurer()
{ {
if (this->Force) if (this->Force && !this->NoRelease)
{ {
PyGILState_Release(this->State); PyGILState_Release(this->State);
} }
...@@ -163,6 +164,7 @@ public: ...@@ -163,6 +164,7 @@ public:
private: private:
PyGILState_STATE State; PyGILState_STATE State;
bool Force; bool Force;
bool NoRelease;
vtkPythonScopeGilEnsurer(const vtkPythonScopeGilEnsurer&); // Not implemented. vtkPythonScopeGilEnsurer(const vtkPythonScopeGilEnsurer&); // Not implemented.
void operator=(const vtkPythonScopeGilEnsurer&); // Not implemented. void operator=(const vtkPythonScopeGilEnsurer&); // Not implemented.
......
...@@ -197,6 +197,7 @@ void vtkPythonInterpreter::Finalize() ...@@ -197,6 +197,7 @@ void vtkPythonInterpreter::Finalize()
if (Py_IsInitialized() != 0) if (Py_IsInitialized() != 0)
{ {
NotifyInterpreters(vtkCommand::ExitEvent); NotifyInterpreters(vtkCommand::ExitEvent);
vtkPythonScopeGilEnsurer gilEnsurer(false, true);
Py_Finalize(); Py_Finalize();
} }
} }
...@@ -331,7 +332,7 @@ int vtkPythonInterpreter::PyMain(int argc, char** argv) ...@@ -331,7 +332,7 @@ int vtkPythonInterpreter::PyMain(int argc, char** argv)
return res; return res;
#else #else
vtkPythonScopeGilEnsurer gilEnsurer; vtkPythonScopeGilEnsurer gilEnsurer( false, true);
return Py_Main(argc, argv); return Py_Main(argc, argv);
#endif #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