Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ngoldbaum
Copy link
Member

Checking Py_REFCNT == 1 is thread-unsafe on the free-threaded build, since refcounts are stored and loaded in free-threading using atomic operations.

Python 3.14 added PyUnstable_Object_IsUniquelyReferenced to replace static refcount checks. I added a backport to pythoncapi-compat in python/pythoncapi-compat#149, which allows me to use the function unconditionally and get correct behavior on 3.13t as well. This relies on some private implementation details on 3.13t, but all that is done in the compat header.

@ngoldbaum ngoldbaum added 00 - Bug 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) 09 - Backport-Candidate PRs tagged should be backported labels Sep 1, 2025
@charris charris merged commit 4e05a13 into numpy:main Sep 1, 2025
77 checks passed
@charris
Copy link
Member

charris commented Sep 1, 2025

Thanks Nathan.

@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants