-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Py_GIL_DISABLED not defined in "free-threaded" Windows C-API extensions #4662
Comments
Do you know how Python was built in this case? If so, was |
This is using |
As I understand, on Windows there is a shared include directory betwen the normal and disable-gil builds, and a single pyconfig.h |
Hi @cvijdea-bd, I disagree with this interpretation, the issue seems to suggest that it needs to be tackled in both CPython and in setuptools. In that regard, Setuptools is open to any PR proposed by members of the community (if I am not wrong none of the active setuptools maintainers participated on the changes in the GIL, so it is best if someone with expertise in the area proposes the change) - so please feel free to open a PR in setuptools if you think that is necessary for free-thread builds. An important aspect of the fix seems to be for CPython to define a coherent value for
Could you please confirm that the value of Also please note that the docs explicitly require Windows user to manually define
So I suppose this means |
Yes, the sysconfig variable correctly reflects the state of Py_GIL_DISABLED
That is true, but that also does not preclude setuptools from handling this automatically. If setuptools does not handle it, then quite literally every library using setuptools to build native extensions have to add code to this effect to their setup.py:
Without the macro defined, the resulting extension will crash the interpreter on import 100% of the time. I just don't see how that could be acceptable default behavior. However I'm not familiar enough with setuptools to really be able to figure out precisely under what conditions the definition should be implicitly added, but the gist of it is that any extension with the free-threaded abi tag (t in "cp313t") MUST be built with |
Thank you for the clarification @cvijdea-bd, I will add the Meanwhile users that need the dependency should follow the Python docs advice and manually define the macro. |
For prior art, CMake defines the macro automatically when the name of the dll import library to be linked ends in "t.lib" (e.g. as in |
When free threaded CPython is installed from the official Windows installer it doesn't have the macro `Py_GIL_DISABLED` properly set becuase its `pyconfig.h` file is shared across the co-installed default build. Define the macro when building free threaded Python extensions on Windows so that each individual C API extension doesn't have to work around this limitation. See pypa/setuptools#4662
When free threaded CPython is installed from the official Windows installer it doesn't have the macro `Py_GIL_DISABLED` properly set becuase its `pyconfig.h` file is shared across the co-installed default build. Define the macro when building free threaded Python extensions on Windows so that each individual C API extension doesn't have to work around this limitation. See pypa/setuptools#4662
I put up a PR in distutils: pypa/distutils#310 |
When free threaded CPython is installed from the official Windows installer it doesn't have the macro `Py_GIL_DISABLED` properly set becuase its `pyconfig.h` file is shared across the co-installed default build. Define the macro when building free threaded Python extensions on Windows so that each individual C API extension doesn't have to work around this limitation. See pypa/setuptools#4662
setuptools version
75.1.0
Python version
3.13
OS
Windows
Additional environment information
No response
Description
When building a native extension against the free-threading build, the
Py_GIL_DISABLED
macro is not defined, which on Windows causes the built extension to crash on import due to linking topython313.dll
instead ofpython313t.dll
.python/cpython#111650 seems to imply that it should be setuptools' job to handle this.
Expected behavior
Py_GIL_DISABLED
macro is defined when buildingif sysconfig.get_config_var("Py_GIL_DISABLED")
.How to Reproduce
The text was updated successfully, but these errors were encountered: