@@ -43,6 +43,7 @@ PythonSystemLoader::~PythonSystemLoader()
43
43
{
44
44
if (this ->pythonSystem )
45
45
{
46
+ py::gil_scoped_acquire gil;
46
47
if (py::hasattr (this ->pythonSystem , " shutdown" ))
47
48
{
48
49
this ->pythonSystem .attr (" shutdown" )();
@@ -54,6 +55,7 @@ void PythonSystemLoader::Configure(
54
55
const Entity &_entity, const std::shared_ptr<const sdf::Element> &_sdf,
55
56
EntityComponentManager &_ecm, EventManager &_eventMgr)
56
57
{
58
+ py::gil_scoped_acquire gil;
57
59
auto [moduleName, hasModule] = _sdf->Get <std::string>(" module_name" , " " );
58
60
if (!hasModule)
59
61
{
@@ -194,13 +196,18 @@ void PythonSystemLoader::CallPythonMethod(py::object _method, Args &&..._args)
194
196
void PythonSystemLoader::PreUpdate (const UpdateInfo &_info,
195
197
EntityComponentManager &_ecm)
196
198
{
199
+ // Add explicit scoped acquire and release of GIL, so that Python
200
+ // Systems can be executed.This acquire and release is only required
201
+ // from the PythonSystem code
202
+ py::gil_scoped_acquire gil;
197
203
CallPythonMethod (this ->preUpdateMethod , _info, &_ecm);
198
204
}
199
205
200
206
// ////////////////////////////////////////////////
201
207
void PythonSystemLoader::Update (const UpdateInfo &_info,
202
208
EntityComponentManager &_ecm)
203
209
{
210
+ py::gil_scoped_acquire gil;
204
211
CallPythonMethod (this ->updateMethod , _info, &_ecm);
205
212
}
206
213
@@ -215,6 +222,7 @@ void PythonSystemLoader::PostUpdate(const UpdateInfo &_info,
215
222
void PythonSystemLoader::Reset (const UpdateInfo &_info,
216
223
EntityComponentManager &_ecm)
217
224
{
225
+ py::gil_scoped_acquire gil;
218
226
CallPythonMethod (this ->resetMethod , _info, &_ecm);
219
227
}
220
228
0 commit comments