|
RTC Toolkit 5.1.0
|
Helper class for managing the lifecycle of an embedded Python interpreter. More...
#include <rtctk/componentFramework/pythonInterpreter.hpp>
Classes | |
| class | SetupFailure |
| This exception is raised when the Python interpreter cannot be initialised properly. More... | |
Public Member Functions | |
| PythonInterpreter (bool init_signal_handlers=true, int argc=0, const char *const *argv=nullptr, bool add_program_dir_to_path=true) | |
| Initialises the embedded Python interpreter. | |
| PythonInterpreter (PyConfig *config, int argc=0, const char *const *argv=nullptr, bool add_program_dir_to_path=true) | |
| Initialises the embedded Python interpreter using a custom configuration. | |
| PythonInterpreter (const PythonInterpreter &)=delete | |
| PythonInterpreter (PythonInterpreter &&)=delete | |
| PythonInterpreter & | operator= (const PythonInterpreter &)=delete |
| PythonInterpreter & | operator= (PythonInterpreter &&)=delete |
| ~PythonInterpreter ()=default | |
Helper class for managing the lifecycle of an embedded Python interpreter.
This class should be instantiated in the main thread, which will initialise an embedded Python interpreter, perform some minimal setup and release the GIL so that other threads can execute Python code. The interpreter will be available as long as the instance of this class is not destroyed, i.e. the lifetime of the Python interpreter is identical to the lifetime of this object.
The following is a canonical example of setting up the Python interpreter to be used in any SRTC component:
Then in any other thread it is possible to execute Python code as long as the GIL is acquired. For example, in the ActivityRunning method that is executed in a separate activity thread, one would place an instantiation of the gil_scoped_acquire RAII helper class at the beginning of a scoped block of code that makes invocations to Python using Pybind11:
|
explicit |
Initialises the embedded Python interpreter.
| [in] | init_signal_handlers | Optional parameter used to skip the registration of signal handlers. (See the Python documentation for details.) |
| [in] | argc | Optional parameter used to populate sys.argv. (See the PySys_SetArgvEx documentation for details.) |
| [in] | argv | Optional parameter used to populate sys.argv. (See the PySys_SetArgvEx documentation for details.) |
| [in] | add_program_dir_to_path | Optional parameter used to populate sys.path. (See the PySys_SetArgvEx documentation for details.) |
|
explicit |
Initialises the embedded Python interpreter using a custom configuration.
| [in] | config | Configuration object used to initialise the embedded Python interpreter. (See the PyConfig and Py_InitializeFromConfig documentation for details.) |
| [in] | argc | Optional parameter used to populate sys.argv. (See the PySys_SetArgvEx documentation for details.) |
| [in] | argv | Optional parameter used to populate sys.argv. (See the PySys_SetArgvEx documentation for details.) |
| [in] | add_program_dir_to_path | Optional parameter used to populate sys.path. (See the PySys_SetArgvEx documentation for details.) |
|
delete |
|
delete |
|
default |
|
delete |
|
delete |