Skip to content

Commit 0c29a08

Browse files
committed
grab the GIL when our plugins are intitializing the interpreter
1 parent fd8d4f2 commit 0c29a08

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pdal/plang/Environment.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,20 @@ EnvironmentPtr Environment::get()
114114

115115
auto init = []()
116116
{
117+
PyGILState_STATE gstate;
118+
119+
// If the interpreter is already initialized, we need to
120+
// grab the GIL and hold it before we go do any Python
121+
// stuff
122+
bool alreadyInitialized(Py_IsInitialized());
123+
if (alreadyInitialized)
124+
gstate = PyGILState_Ensure();
125+
117126
g_environment = new Environment();
127+
128+
if (alreadyInitialized)
129+
PyGILState_Release(gstate);
118130
};
119-
gil_scoped_acquire acquire;
120131
std::call_once(flag, init);
121132
return g_environment;
122133
}

pdal/plang/gil.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class gil_scoped_release {
4545
};
4646

4747

48+
49+
4850
} // plang
4951

5052
} // pdal

0 commit comments

Comments
 (0)