python / python/cpython

Add C API equivalent for `sys._is_gil_enabled()`

Open
#143,747 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending topic-C-API topic-free-threading type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

sys._is_gil_enabled is documented as a CPython implementation detail - it would be good to have a C API to expose this in a stable way to C modules. Possibly, something like

int PyInterpreterState_IsGilEnabled(PyInterpreterState *interp)

We'd like to have a stable way to expose this information downstream, https://github.com/jpy-consortium/jpy/pull/218

Has this already been discussed elsewhere?

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

Links to previous discussion of this feature:

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing sys._is_gil_enabled documentation and the linked discussion about a C API for querying GIL state. Review the downstream jpy pull request and existing stable C API conventions before determining the agreed API shape; done means a documented, stable C API is available for C modules.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.