Skip to content

[Python-C] _PyThreadState_UncheckedGet() changed behavior in python 3.12 and code from 3.11 no longer works #131346

@AnnaAraslanova

Description

@AnnaAraslanova

Bug report

Bug description:

Hello

I have code that works in Python 3.11 and no longer works in Python 3.12. I'd like to get an explanation of what changed as I see that the full GIL Python-C API was rewritten in Python 3.12 (./Python/pystate.c).

Basically I check that GIL lock is held by checking it this way:

bool IsGilHeld() {
  return _PyThreadState_UncheckedGet() != nullptr;
}

And I test it with doing an intencive operation:

# Simulate some heavy ML workload.
for _ in range(10000000):
    _ = random.random() * random.random()

In Python 3.11 _PyThreadState_UncheckedGet() returns a pointer at some point and in 3.12 the function always returns a nullptr.

@ericsnowcurrently

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedtopic-C-API

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions