From 7560da40727cb204940c9e20fc3273fcfdf83692 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Thu, 27 Feb 2025 21:47:55 -0500 Subject: [PATCH] setup: Don't use stable ABI for free-threaded builds Free-threading builds unfortunately require some intrusive build changes, so we must make the stable ABI optional python 3.13t. --- setup.py | 9 +++++++-- tornado/test/util.py | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 0b175af8..de6cd3f0 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,7 @@ import os import platform import setuptools +import sysconfig kwargs = {} @@ -35,6 +36,9 @@ if ( platform.python_implementation() == "CPython" and os.environ.get("TORNADO_EXTENSION") != "0" ): + + can_use_limited_api = not sysconfig.get_config_var("Py_GIL_DISABLED") + # This extension builds and works on pypy as well, although pypy's jit # produces equivalent performance. kwargs["ext_modules"] = [ @@ -46,12 +50,13 @@ if ( optional=os.environ.get("TORNADO_EXTENSION") != "1", # Use the stable ABI so our wheels are compatible across python # versions. - py_limited_api=True, + py_limited_api=can_use_limited_api, define_macros=[("Py_LIMITED_API", "0x03090000")], ) ] - kwargs["options"] = {"bdist_wheel": {"py_limited_api": "cp39"}} + if can_use_limited_api: + kwargs["options"] = {"bdist_wheel": {"py_limited_api": "cp39"}} setuptools.setup( diff --git a/tornado/test/util.py b/tornado/test/util.py index 25dd2000..c409b4ce 100644 --- a/tornado/test/util.py +++ b/tornado/test/util.py @@ -3,6 +3,7 @@ import os import platform import socket import sys +import sysconfig import textwrap import typing import unittest @@ -21,7 +22,11 @@ skipIfNonUnix = unittest.skipIf( skipIfNoNetwork = unittest.skipIf("NO_NETWORK" in os.environ, "network access disabled") skipNotCPython = unittest.skipIf( - platform.python_implementation() != "CPython", "Not CPython implementation" + # "CPython" here essentially refers to the traditional synchronous refcounting GC, + # so we skip these tests in free-threading builds of cpython too. + platform.python_implementation() != "CPython" + or sysconfig.get_config_var("Py_GIL_DISABLED"), + "Not CPython implementation", ) -- 2.47.2