LibreOffice Module pyuno (master) 1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
pyuno::PyThreadAttach Class Reference

helper class for attaching the current thread to the python runtime. More...

#include <pyuno.hxx>

Public Member Functions

 PyThreadAttach (PyInterpreterState *interp)
 Creates a new python threadstate and acquires the global interpreter lock. More...
 
 ~PyThreadAttach ()
 Releases the global interpreter lock and destroys the thread state. More...
 

Private Member Functions

 PyThreadAttach (const PyThreadAttach &)=delete
 
PyThreadAttachoperator= (const PyThreadAttach &)=delete
 

Private Attributes

PyThreadState * tstate
 
bool m_isNewState
 

Detailed Description

helper class for attaching the current thread to the python runtime.

Attaching is done creating a new threadstate for the given interpreter and acquiring the global interpreter lock.

Usage:

... don't use python here { PyThreadAttach guard( PyInterpreterState_Head() ); { ... do whatever python code you want { PyThreadDetach antiguard; ... don't use python here } ... do whatever python code you want } } ... don't use python here

Note: The additional scope brackets after the PyThreadAttach are needed, e.g. when you would leave them away, dtors of potential pyrefs may be called after the thread has detached again.

Definition at line 271 of file pyuno.hxx.

Constructor & Destructor Documentation

◆ PyThreadAttach() [1/2]

pyuno::PyThreadAttach::PyThreadAttach ( const PyThreadAttach )
privatedelete

◆ PyThreadAttach() [2/2]

pyuno::PyThreadAttach::PyThreadAttach ( PyInterpreterState *  interp)

Creates a new python threadstate and acquires the global interpreter lock.

precondition: The current thread MUST NOT hold the global interpreter lock. postcondition: The global interpreter lock is acquired

Exceptions
css::uno::RuntimeExceptionin case no pythread state could be created

Definition at line 955 of file pyuno_runtime.cxx.

References m_isNewState, and tstate.

◆ ~PyThreadAttach()

pyuno::PyThreadAttach::~PyThreadAttach ( )

Releases the global interpreter lock and destroys the thread state.

Definition at line 971 of file pyuno_runtime.cxx.

References m_isNewState, and tstate.

Member Function Documentation

◆ operator=()

PyThreadAttach & pyuno::PyThreadAttach::operator= ( const PyThreadAttach )
privatedelete

Member Data Documentation

◆ m_isNewState

bool pyuno::PyThreadAttach::m_isNewState
private

Definition at line 274 of file pyuno.hxx.

Referenced by PyThreadAttach(), and ~PyThreadAttach().

◆ tstate

PyThreadState* pyuno::PyThreadAttach::tstate
private

Definition at line 273 of file pyuno.hxx.

Referenced by PyThreadAttach(), and ~PyThreadAttach().


The documentation for this class was generated from the following files: