Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ def awscrt_ext():
extra_objects = []
define_macros = []
py_limited_api = False
has_gil = True

libraries = [x.libname for x in AWS_LIBS]

Expand Down Expand Up @@ -531,8 +532,15 @@ def awscrt_ext():
else:
extra_link_args += ['-Wl,--fatal-warnings']

if hasattr(sys, '_is_gil_enabled'):
has_gil = sys._is_gil_enabled()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just happened to come across this. You don't want to spell it this way, because the GIL might be disabled or enabled at runtime, which is what this API checks.

Instead, you want to check if you're using a free-threaded interpreter, which I spell like:

import sysconfig;

FREE_THREADED_BUILD = sysconfig.get_config_var("Py_GIL_DISABLED")

And then switch on whether to use the limited API based on that.


# prefer building with stable ABI, so a wheel can work with multiple major versions
if sys.version_info >= (3, 13):
if not has_gil and sys.version_info == (3, 14):
# 3.14 free threaded (aka no gil) does not support limited api.
# disable it for now. 3.15 promises to support limited api + free threading combo
py_limited_api = False
elif sys.version_info >= (3, 13):
# 3.13 deprecates PyWeakref_GetObject(), adds alternative
define_macros.append(('Py_LIMITED_API', '0x030D0000'))
py_limited_api = True
Expand Down