Skip to content

Commit ed45e7b

Browse files
committed
Merge pull request pypa/distutils#310 from colesbury.
Set `Py_GIL_DISABLED=1` for free threaded Python on Windows.
2 parents 2517976 + 52848a0 commit ed45e7b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

distutils/command/build_ext.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
)
2424
from ..extension import Extension
2525
from ..sysconfig import customize_compiler, get_config_h_filename, get_python_version
26-
from ..util import get_platform, is_mingw
26+
from ..util import get_platform, is_mingw, is_freethreaded
2727

2828
# An extension name is just a dot-separated list of Python NAMEs (ie.
2929
# the same as a fully-qualified module name).
@@ -333,6 +333,12 @@ def run(self): # noqa: C901
333333
if os.name == 'nt' and self.plat_name != get_platform():
334334
self.compiler.initialize(self.plat_name)
335335

336+
# The official Windows free threaded Python installer doesn't set
337+
# Py_GIL_DISABLED because its pyconfig.h is shared with the
338+
# default build, so define it here (pypa/setuptools#4662).
339+
if os.name == 'nt' and is_freethreaded():
340+
self.compiler.define_macro('Py_GIL_DISABLED', '1')
341+
336342
# And make sure that any compile/link-related options (which might
337343
# come from the command-line or from the setup script) are set in
338344
# that CCompiler object -- that way, they automatically apply to

distutils/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,7 @@ def is_mingw():
503503
get_platform() starts with 'mingw'.
504504
"""
505505
return sys.platform == 'win32' and get_platform().startswith('mingw')
506+
507+
def is_freethreaded():
508+
"""Return True if the Python interpreter is built with free threading support."""
509+
return bool(sysconfig.get_config_var('Py_GIL_DISABLED'))

0 commit comments

Comments
 (0)