From fda90bc4fcbdbaed9b77e4ffb96d31a7ca336d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sat, 19 Oct 2024 16:34:00 +0200 Subject: [PATCH] feat: Do not use C speedups on Python 3.13+ freethreading Do not enable C speedups by default if running Python 3.13+ in freethreading mode (with GIL disabled). Since the extension does not support this mode explicitly at the moment, loading it would cause CPython to reenable GIL with a warning and penalize the whole environment. Discussed in issue #330. --- CHANGES.rst | 5 +++++ src/zope/interface/_compat.py | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index ad3f6759..c1c21193 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,11 @@ 7.1.1 (unreleased) ================== +- Disable automatically using C speedups when Python 3.13 is used + in freethreading mode for the time being (at least until the C + extension gains support for freethreading mode). + (`#330 `_) + 7.1.0 (2024-10-10) ================== diff --git a/src/zope/interface/_compat.py b/src/zope/interface/_compat.py index bc3f8671..f6a95581 100644 --- a/src/zope/interface/_compat.py +++ b/src/zope/interface/_compat.py @@ -74,8 +74,10 @@ def _should_attempt_c_optimizations(): """ Return a true value if we should attempt to use the C optimizations. - This takes into account whether we're on PyPy and the value of the - ``PURE_PYTHON`` environment variable, as defined in `_use_c_impl`. + This takes into account whether we're on PyPy, whether you're using + a freethreading version of Python 3.13+ (where importing + the speedups would enable GIL) and the value of the ``PURE_PYTHON`` + environment variable, as defined in `_use_c_impl`. """ is_pypy = hasattr(sys, 'pypy_version_info') @@ -83,6 +85,8 @@ def _should_attempt_c_optimizations(): return True if is_pypy: return False + if sys.version_info >= (3, 13) and not sys._is_gil_enabled(): + return False return not _c_optimizations_ignored()