CPythonGil Struct Reference

#include <cpython.h>

Detailed Description

The CPythonGil class acquires the GIL lock upon creation and releases this upon destruction (usually at the end of a code block). This simplifies cases where your code contains many return statements where you'd otherwise have to manually unlock the GIL before returning. Only use CPythonGil for a short block of your code. Do not use ScopedLock mindlessly at the beginning of a function! This will block all other threads for the whole runtime of the function to execute Python code, which is usually much longer than required. A few Python functions unlock the GIL and lock it again before returning (e.g. several file operation functions), but this is up to the function and you need to check their corresponding documentation what their behavior is.


See also

Public Member Functions

 CPythonGil (CPythonLibraryInterface *pylib)
 CPythonGil (CPythonLibraryInterface *pylib, Bool lock)
 ~CPythonGil ()

Public Attributes


Constructor & Destructor Documentation

◆ CPythonGil() [1/2]

CPythonGil ( CPythonLibraryInterface pylib)

◆ CPythonGil() [2/2]

CPythonGil ( CPythonLibraryInterface pylib,
Bool  lock 

◆ ~CPythonGil()

~CPythonGil ( )

Member Data Documentation

◆ _lib

◆ _state