diff --git a/python/test/gravity.sdf b/python/test/gravity.sdf index c2ae2a17cd..301fa6ee5d 100644 --- a/python/test/gravity.sdf +++ b/python/test/gravity.sdf @@ -17,6 +17,11 @@ 1.0 + + plugins.test_model_system + + diff --git a/src/systems/python_system_loader/PythonSystemLoader.cc b/src/systems/python_system_loader/PythonSystemLoader.cc index d9dcdb0547..4cf8e55355 100644 --- a/src/systems/python_system_loader/PythonSystemLoader.cc +++ b/src/systems/python_system_loader/PythonSystemLoader.cc @@ -43,6 +43,7 @@ PythonSystemLoader::~PythonSystemLoader() { if (this->pythonSystem) { + py::gil_scoped_acquire gil; if (py::hasattr(this->pythonSystem, "shutdown")) { this->pythonSystem.attr("shutdown")(); @@ -54,6 +55,7 @@ void PythonSystemLoader::Configure( const Entity &_entity, const std::shared_ptr &_sdf, EntityComponentManager &_ecm, EventManager &_eventMgr) { + py::gil_scoped_acquire gil; auto [moduleName, hasModule] = _sdf->Get("module_name", ""); if (!hasModule) { @@ -194,6 +196,10 @@ void PythonSystemLoader::CallPythonMethod(py::object _method, Args &&..._args) void PythonSystemLoader::PreUpdate(const UpdateInfo &_info, EntityComponentManager &_ecm) { + // Add explicit scoped acquire and release of GIL, so that Python + // Systems can be executed.This acquire and release is only required + // from the PythonSystem code + py::gil_scoped_acquire gil; CallPythonMethod(this->preUpdateMethod, _info, &_ecm); } @@ -201,6 +207,7 @@ void PythonSystemLoader::PreUpdate(const UpdateInfo &_info, void PythonSystemLoader::Update(const UpdateInfo &_info, EntityComponentManager &_ecm) { + py::gil_scoped_acquire gil; CallPythonMethod(this->updateMethod, _info, &_ecm); } @@ -215,6 +222,7 @@ void PythonSystemLoader::PostUpdate(const UpdateInfo &_info, void PythonSystemLoader::Reset(const UpdateInfo &_info, EntityComponentManager &_ecm) { + py::gil_scoped_acquire gil; CallPythonMethod(this->resetMethod, _info, &_ecm); }