Skip to content

Commit fda90bc

Browse files
committed
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.
1 parent d246ed1 commit fda90bc

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGES.rst

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
7.1.1 (unreleased)
66
==================
77

8+
- Disable automatically using C speedups when Python 3.13 is used
9+
in freethreading mode for the time being (at least until the C
10+
extension gains support for freethreading mode).
11+
(`#330 <https://github.com/zopefoundation/zope.interface/issues/330>`_)
12+
813

914
7.1.0 (2024-10-10)
1015
==================

src/zope/interface/_compat.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,19 @@ def _should_attempt_c_optimizations():
7474
"""
7575
Return a true value if we should attempt to use the C optimizations.
7676
77-
This takes into account whether we're on PyPy and the value of the
78-
``PURE_PYTHON`` environment variable, as defined in `_use_c_impl`.
77+
This takes into account whether we're on PyPy, whether you're using
78+
a freethreading version of Python 3.13+ (where importing
79+
the speedups would enable GIL) and the value of the ``PURE_PYTHON``
80+
environment variable, as defined in `_use_c_impl`.
7981
"""
8082
is_pypy = hasattr(sys, 'pypy_version_info')
8183

8284
if _c_optimizations_required():
8385
return True
8486
if is_pypy:
8587
return False
88+
if sys.version_info >= (3, 13) and not sys._is_gil_enabled():
89+
return False
8690
return not _c_optimizations_ignored()
8791

8892

0 commit comments

Comments
 (0)