diff --git a/pdal/plang/Environment.cpp b/pdal/plang/Environment.cpp index 5f9e98d..a8e7c27 100644 --- a/pdal/plang/Environment.cpp +++ b/pdal/plang/Environment.cpp @@ -114,9 +114,20 @@ EnvironmentPtr Environment::get() auto init = []() { + PyGILState_STATE gstate; + + // If the interpreter is already initialized, we need to + // grab the GIL and hold it before we go do any Python + // stuff + bool alreadyInitialized(Py_IsInitialized()); + if (alreadyInitialized) + gstate = PyGILState_Ensure(); + g_environment = new Environment(); + + if (alreadyInitialized) + PyGILState_Release(gstate); }; - gil_scoped_acquire acquire; std::call_once(flag, init); return g_environment; } diff --git a/pdal/plang/gil.hpp b/pdal/plang/gil.hpp index 2c03aa4..5ce57e2 100644 --- a/pdal/plang/gil.hpp +++ b/pdal/plang/gil.hpp @@ -45,6 +45,8 @@ class gil_scoped_release { }; + + } // plang } // pdal