Skip to content

Commit

Permalink
feat: Do not use C speedups on Python 3.13+ freethreading
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mgorny committed Oct 19, 2024
1 parent d246ed1 commit b3e4385
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/zope/interface/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,19 @@ 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')

if _c_optimizations_required():
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()


Expand Down

0 comments on commit b3e4385

Please sign in to comment.