Skip to content

Commit b3e4385

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 b3e4385

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/zope/interface/_compat.py

Lines changed: 6 additions & 2 deletions
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)