GeezerVison is showing github.com — gh-140544: Always assume that thread locals are available by ZeroIntensity · Pull Request #140690 · python/cpython
Conversation
ZeroIntensity
commented
Oct 27, 2025
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Python has required thread local support since 3.12. By assuming that thread locals are always supported, we can improve the performance of third-party extensions by allowing them to access the attached thread and interpreter states directly.
cc @cdce8p
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
ZeroIntensity
changed the title
gh-140544: Always assume the HAVE_THREAD_LOCAL macro is defined.
gh-140544: Always assume that thread locals are available
Oct 27, 2025
cdce8p
commented
Oct 27, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Hmm, I'm still getting the same error I mentioned earlier.
In file included from /.../cpython/Include/internal/pycore_object.h:12: (diff)
In file included from /.../cpython/Include/internal/pycore_gc.h:12: (diff)
/.../cpython/Include/internal/pycore_pystate.h:93:8: error: unknown type name '_Py_thread_local' (diff)
extern _Py_thread_local PyThreadState *_Py_tss_tstate; (diff)
^ (diff)
/.../cpython/Include/internal/pycore_pystate.h:93:38: error: expected ';' after top level declarator (diff)
extern _Py_thread_local PyThreadState *_Py_tss_tstate; (diff)
^ (diff)
; (diff)
/.../cpython/Include/internal/pycore_pystate.h:94:8: error: unknown type name '_Py_thread_local' (diff)
extern _Py_thread_local PyInterpreterState *_Py_tss_interp; (diff)
^ (diff)
/.../cpython/Include/internal/pycore_pystate.h:94:43: error: expected ';' after top level declarator (diff)
extern _Py_thread_local PyInterpreterState *_Py_tss_interp; (diff)
^ (diff)
; (diff)
/.../cpython/Include/internal/pycore_pystate.h:119:12: error: use of undeclared identifier '_Py_tss_tstate' (diff)
return _Py_tss_tstate; (diff)
^ (diff)
/.../cpython/Include/internal/pycore_pystate.h:213:12: error: use of undeclared identifier '_Py_tss_interp' (diff)
return _Py_tss_interp; (diff)
^ (diff)
6 errors generated. (diff)
Somehow the # ifdef Py_BUILD_CORE check fails, even though mypyc defines it.
https://github.com/python/mypy/blob/v1.18.2/mypyc/lib-rt/pythonsupport.h#L16-L18
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Do I need to pass Py_BUILD_CORE through to my local cpython build? This is my current build setup
make clean
./configure --with-openssl=$(brew --prefix openssl@3)
make -j4 -s
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Hm, you're defining Py_BUILD_CORE after Python.h has been included, so pyport.h isn't seeing it. I'm not sure if that's something we intended to support.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Hm, you're defining Py_BUILD_CORE after Python.h has been included, so pyport.h isn't seeing it. I'm not sure if that's something we intended to support.
That hasn't been an issue so far. The check here works fine / if I remove Py_BUILD_CORE from mypyc I get the error as expected.
|
#ifndef Py_BUILD_CORE |
|
# error "this header requires Py_BUILD_CORE define" |
|
#endif |
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This fixes extensions that define Py_BUILD_CORE after including
Python.h, but before including pycore_pystate.h, such as mypyc.
|
I just pushed a new commit, where _Py_thread_local is moved to pycore_pystate.h. Can you test that?
|
cdce8p reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
I just pushed a new commit, where _Py_thread_local is moved to pycore_pystate.h. Can you test that?
This works now.
--
Hm, you're defining Py_BUILD_CORE after Python.h has been included, so pyport.h isn't seeing it. I'm not sure if that's something we intended to support.
I missed that mypyc is defining Py_BUILD_CORE before including any internal/** headers. Though that's much simpler than doing the same for Python.h which is included nearly everywhere.
|
ZeroIntensity reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
@cdce8p Would you please check that mypyc still works after the new changes?
|
ZeroIntensity and cdce8p reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
@cdce8p Would you please check that mypyc still works after the new changes?
Just ran the whole test suite again. Looks good.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
StanFromIreland
pushed a commit
to StanFromIreland/cpython
that referenced
this pull request
Dec 6, 2025
…onGH-140690)
Python has required thread local support since 3.12 (see pythonGH-103324). By assuming that thread locals are always supported, we can improve the performance of third-party extensions by allowing them to access the attached thread and interpreter states directly.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|