class PythonInterpreterState

Overview

Initializes the python interpreter as well as python threading. More…

#include <python_interpreter_state.h>

class PythonInterpreterState {
public:
    // construction

    PythonInterpreterState(
        int argc,
        const char*const* argv,
        bool allowThreads = false
    );

    PythonInterpreterState(
        int argc,
        const std::vector<const char*>& argv,
        bool allowThreads = false
    );

    PythonInterpreterState(bool allowThreads = false);

    // methods

    void allowThreads();
    bool threadsAllowed() const;
    void endAllowThreads();
};

Detailed Documentation

Initializes the python interpreter as well as python threading.

Construction

PythonInterpreterState(
    int argc,
    const char*const* argv,
    bool allowThreads = false
)

Constructor. Initializes Python with the given start parameters, enables threading, and releases GIL.

Parameters:

argc

main() ‘s argc

argv

main() ‘s argv

PythonInterpreterState(
    int argc,
    const std::vector<const char*>& argv,
    bool allowThreads = false
)

Constructor. Initializes Python with the given start parameters, enables threading, and releases GIL.

Parameters:

argc

main() ‘s argc

argv

main() ‘s argv

PythonInterpreterState(bool allowThreads = false)

Constructor. Initializes Python with the no start parameters, enables threading, and releases GIL.

Parameters:

argc

main() ‘s argc

argv

main() ‘s argv

Methods

void allowThreads()

Allow execution of other threads. If this is set, main thread may not execute python code.

bool threadsAllowed() const

Are threads currently allowed?

Returns:

Returns true if allowed, false otherwise

void endAllowThreads()

Halt other threads from executin. This is required if python code should be executed in the main thread.