gazebosim / gz-sim

Open source robotics simulator. The latest version of Gazebo.
https://gazebosim.org
Apache License 2.0
719 stars 272 forks source link

PythonSystemLoader does not release GIL, which causes issues when running a server with a python system #2613

Open AmalDevHaridevan opened 2 months ago

AmalDevHaridevan commented 2 months ago

Desired behavior

My scenario is this: There is a Python system plugin, which is attached to my model. I use TestFixture in Python to run the server with this model, however, due to GIL not being explicitly released in the PythonSystemLoader, the TestFixture cannot execute its python method. The error I got was as follows:

Screenshot from 2024-09-10 12-18-29

Implementation suggestion

To overcome this issue, we need to do a scoped_acquire of GIL explicitly and then perform scoped_release after each of the system methods, namely, PreUpdate, Update, PostUpdate of the PythonSystem, so the GIL can be accessed by the TestFixture after. As a safety mechanism, for future, I also added the scoped_acquire and release of GIL within the pybind code for TestFixture. After fixing the results are as follows: Screenshot from 2024-09-10 12-20-26

Additional context

OS: Ubuntu 22.04 GZ Harmonic