CPythonGil Struct Reference

#include <cpython.h>

详细描述

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.

THREADSAFE.

另请参阅
CPythonGil

公共成员函数

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

Public Attributes

CPythonLibraryInterface _lib
PYGILSTATE   _state

构造函数 & 析构函数文档编制

◆  CPythonGil() [1/2]

CPythonGil ( CPythonLibraryInterface pylib )
explicit

◆  CPythonGil() [2/2]

CPythonGil ( CPythonLibraryInterface pylib ,
Bool   lock  
)
explicit

◆  ~CPythonGil()

~ CPythonGil ( )

Member Data Documentation

◆  _lib

CPythonLibraryInterface * _lib

◆  _state

PYGILSTATE _state