ScopedGilAcquire

class ScopedGilAcquire

The ScopedGilAcquire class is a utility class that provides a scoped acquisition and release of the Global Interpreter Lock (GIL).

The ScopedGilAcquire is used to safely acquire and release the GIL within a specific scope, ensuring that the Python interpreter is protected from concurrent access by multiple threads.

Public Functions

inline explicit ScopedGilAcquire(std::string callback_name)

Acquiring the GIL within the given scope for safe interaction with the Python interpreter.

If the GIL is already acquired, it logs the action without re-acquiring.

Parameters:

callback_name – A string representing the name of the scope or function acquiring the GIL, used for debugging and logging purposes.

inline ~ScopedGilAcquire()

Destructor for the ScopedGilAcquire class, releasing the Global Interpreter Lock (GIL).

The destructor ensures the proper release of the GIL when the ScopedGilAcquire object goes out of scope, if and only-if the GIL was acquired at first place.