Skip to content

Proposal: Expose _PyEval_IsGILEnabled as an unstable CPython C API #144008

@VanshAgarwal24036

Description

@VanshAgarwal24036

I’d like to propose exposing _PyEval_IsGILEnabled as an unstable, CPython-specific C API.

Context

  • CPython recently added sys._is_gil_enabled() as a Python-level diagnostic API.
  • Some C extensions would like to make similar diagnostic or configuration decisions without calling back into Python (e.g. via PySys_GetAttr + PyObject_CallNoArgs).
  • During discussion on Discourse, a CPython core developer suggested that exposing an existing helper such as _PyEval_IsGILEnabled would be preferable to introducing a new API that requires passing a PyInterpreterState *.

Discourse discussion

https://discuss.python.org/t/c-api-for-querying-whether-the-gil-is-enabled-pyinterpreterstate-isgilenabled/105776

Related GitHub issue

#143747

Proposal

  • Expose _PyEval_IsGILEnabled as an unstable, CPython-specific C API.
  • The API would live under Include/cpython/ and would not be part of the stable ABI.
  • The intended use is diagnostics, reporting, or choosing reasonable defaults in C extensions (e.g. selecting threading vs multiprocessing backends), not for controlling GIL behavior.

I’m seeking feedback and approval from the C API Working Group on whether exposing this API is acceptable before proceeding with any implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions