This class is used to maintain the Python interpreter. More...
#include <pythonutils.h>
Static Public Member Functions | |
static void | addThread () |
static void | deleteThread () |
static void | execute (const char *) |
static PyObject * | getModule () |
static const char * | getPythonEncoding () |
static void | initialize () |
static void | registerGlobalMethod (const char *, PyCFunctionWithKeywords, int, const char *) |
static void | registerGlobalMethod (const char *, PyCFunction, int, const char *, bool=true) |
This class is used to maintain the Python interpreter.
A single interpreter is used throughout the lifetime of the application.
The implementation is implemented in a thread-safe way (within the limitations of the Python threading model, of course).
During the initialization the code checks for a file 'init.py' in its search path and, if it does exist, the statements in the file will be executed. In this way a library of globally available functions can easily be initialized.
The stderr and stdout streams of Python are redirected by default to the frePPLe log stream.
The following frePPLe functions are available from within Python.
All of these are in the module called frePPLe.
Definition at line 140 of file pythonutils.h.
void frepple::utils::PythonInterpreter::addThread | ( | ) | [static] |
Create a new Python thread state.
Each OS-level thread needs to initialize a Python thread state as well. When a new thread is created in the OS, this method should be called to create a Python thread state as well.
See the Python PyGILState_Ensure API.
Definition at line 169 of file pythonutils.cpp.
void frepple::utils::PythonInterpreter::deleteThread | ( | ) | [static] |
Delete a Python thread state.
Each OS-level thread has a Python thread state. When an OS thread is deleted, this method should be called to delete the Python thread state as well.
See the Python PyGILState_Release API.
Definition at line 185 of file pythonutils.cpp.
void frepple::utils::PythonInterpreter::execute | ( | const char * | cmd | ) | [static] |
Execute some python code.
Definition at line 198 of file pythonutils.cpp.
static PyObject* frepple::utils::PythonInterpreter::getModule | ( | ) | [inline, static] |
Return a pointer to the main extension module.
Definition at line 166 of file pythonutils.h.
static const char* frepple::utils::PythonInterpreter::getPythonEncoding | ( | ) | [inline, static] |
Return the preferred encoding of the Python interpreter.
Definition at line 169 of file pythonutils.h.
void frepple::utils::PythonInterpreter::initialize | ( | ) | [static] |
Initializes the interpreter.
Definition at line 99 of file pythonutils.cpp.
void frepple::utils::PythonInterpreter::registerGlobalMethod | ( | const char * | c, | |
PyCFunctionWithKeywords | f, | |||
int | i, | |||
const char * | d | |||
) | [static] |
Register a new method to Python.
Definition at line 303 of file pythonutils.cpp.
void frepple::utils::PythonInterpreter::registerGlobalMethod | ( | const char * | name, | |
PyCFunction | method, | |||
int | flags, | |||
const char * | doc, | |||
bool | lock = true | |||
) | [static] |
Register a new method to Python.
Arguments:
Definition at line 242 of file pythonutils.cpp.