install()
Start guarding imports.
Usage
install(action=None)import gilguard calls this for you, so you only need it to choose the action in code, or to start guarding again after uninstall().
Before it starts guarding, it checks the interpreter. On a standard build, or if the GIL is already on, it reports that straight away instead.
Parameters
action: str | None = None-
"raise"to raise GILEnabledError,"warn"to emit GILGuardWarning and keep running, or"off"to do nothing.Nonereads theGILGUARD_ACTIONenvironment variable and falls back to"raise".
Raises
ValueError-
If the action is not one of
raise,warnoroff. GILEnabledError-
If the action is
raiseand the interpreter is a standard build, or the GIL is already enabled.
Examples
Switch to warn mode in code instead of through the environment. The hook is already installed, so this only changes what it does:
import gilguard
gilguard.install(action='warn')install(action='off') on an installed guard removes it, the same as uninstall().