Skip to content

Commit

Permalink
grab the GIL when our plugins are intitializing the interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Jan 2, 2024
1 parent fd8d4f2 commit 0c29a08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pdal/plang/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions pdal/plang/gil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class gil_scoped_release {
};




} // plang

} // pdal

0 comments on commit 0c29a08

Please sign in to comment.