Skip to content

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

@AmalDevHaridevan

Description

@AmalDevHaridevan

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

To do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions