mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-117514: Add sys._is_gil_enabled() function (#118514)
The function returns `True` or `False` depending on whether the GIL is currently enabled. In the default build, it always returns `True` because the GIL is always enabled.
This commit is contained in:
parent
24e643d4ef
commit
2dae505e87
5 changed files with 67 additions and 1 deletions
30
Python/clinic/sysmodule.c.h
generated
30
Python/clinic/sysmodule.c.h
generated
|
|
@ -1485,6 +1485,34 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(sys__is_gil_enabled__doc__,
|
||||
"_is_gil_enabled($module, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return True if the GIL is currently enabled and False otherwise.");
|
||||
|
||||
#define SYS__IS_GIL_ENABLED_METHODDEF \
|
||||
{"_is_gil_enabled", (PyCFunction)sys__is_gil_enabled, METH_NOARGS, sys__is_gil_enabled__doc__},
|
||||
|
||||
static int
|
||||
sys__is_gil_enabled_impl(PyObject *module);
|
||||
|
||||
static PyObject *
|
||||
sys__is_gil_enabled(PyObject *module, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
int _return_value;
|
||||
|
||||
_return_value = sys__is_gil_enabled_impl(module);
|
||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = PyBool_FromLong((long)_return_value);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
#ifndef SYS_GETWINDOWSVERSION_METHODDEF
|
||||
#define SYS_GETWINDOWSVERSION_METHODDEF
|
||||
#endif /* !defined(SYS_GETWINDOWSVERSION_METHODDEF) */
|
||||
|
|
@ -1528,4 +1556,4 @@ exit:
|
|||
#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
|
||||
#define SYS_GETANDROIDAPILEVEL_METHODDEF
|
||||
#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
|
||||
/*[clinic end generated code: output=518424ee03e353b0 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=352ac7a0085e8a1f input=a9049054013a1b77]*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue