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.
- See also
- CPythonGil