From 1c7cb0aaf24f135e4ffded5a39387514f862c92e Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Sat, 18 May 2024 12:43:20 -0400 Subject: [PATCH] Don't build with limited API for 3.13 free-threaded build (#2402) The `--disable-gil` configuration of CPython 3.13 does not currently support the limited API. Signed-off-by: Sam Gross --- HISTORY.rst | 1 + setup.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 15333dbaf..a53590555 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -14,6 +14,7 @@ been reused. This makes `process_iter()`_ around 20x times faster. - 2396_: a new ``psutil.process_iter.cache_clear()`` API can be used the clear `process_iter()`_ internal cache. +- 2401_, Support building with free-threaded CPython 3.13. - 2407_: `Process.connections()`_ was renamed to `Process.net_connections()`_. The old name is still available, but it's deprecated (triggers a ``DeprecationWarning``) and will be removed in the future. diff --git a/setup.py b/setup.py index 7c59f5645..3c7900669 100755 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ import struct import subprocess import sys +import sysconfig import tempfile import warnings @@ -65,6 +66,7 @@ PY37_PLUS = sys.version_info[:2] >= (3, 7) CP36_PLUS = PY36_PLUS and sys.implementation.name == "cpython" CP37_PLUS = PY37_PLUS and sys.implementation.name == "cpython" +Py_GIL_DISABLED = sysconfig.get_config_var("Py_GIL_DISABLED") macros = [] if POSIX: @@ -118,10 +120,10 @@ def get_version(): # Py_LIMITED_API lets us create a single wheel which works with multiple # python versions, including unreleased ones. -if bdist_wheel and CP36_PLUS and (MACOS or LINUX): +if bdist_wheel and CP36_PLUS and (MACOS or LINUX) and not Py_GIL_DISABLED: py_limited_api = {"py_limited_api": True} macros.append(('Py_LIMITED_API', '0x03060000')) -elif bdist_wheel and CP37_PLUS and WINDOWS: +elif bdist_wheel and CP37_PLUS and WINDOWS and not Py_GIL_DISABLED: # PyErr_SetFromWindowsErr / PyErr_SetFromWindowsErrWithFilename are # part of the stable API/ABI starting with CPython 3.7 py_limited_api = {"py_limited_api": True}