You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR creates a new class that simplifies initialization of python threads, as well as acquiring / releasing the Python global interpreter lock in various contexts.
Use cases include:
1. Ensuring that Py_Initialize() is properly called at the beginning of a program that is expected to interact with the python interpreter, and also that Py_Finalize() is called when the program is finished.
2. Ensuring that the current thread state is saved and the GIL released as necessary, e.g. for IO operations, and then the thread state is restored on completion.
3. Ensuring that the GIL is acquired for one-off interaction with the python interpreter, and released when complete.
A G3PythonContext object is used throughout the library code for cases 2 and 3. Case 1 is handled by a G3PythonInterpreter object constructed at the main program/thread level. If the python interpreter has not been initialized (i.e. the compiled program is expected to be purely in C++), then the library context objects are essentially no-op. If the python interpreter is initialized (e.g. inside a python program or command-line interface), then these library context objects will handle the GIL appropriately.
See the examples/cppexample.cxx C++ program for a simple implementation of the above behavior in a compiled program.
Closes#145.
---------
Co-authored-by: Cosmin Deaconu <[email protected]>
See potential implementation in #69, which can be split off into a separate PR.
The text was updated successfully, but these errors were encountered: