File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """Test that the GIL is disabled on free-threaded Python builds."""
2+
3+ from __future__ import annotations
4+
5+ import sys
6+ import sysconfig
7+
8+ import pytest
9+
10+ _is_free_threaded = bool (sysconfig .get_config_var ("Py_GIL_DISABLED" ))
11+
12+
13+ @pytest .mark .skipif (not _is_free_threaded , reason = "not a free-threaded python build" )
14+ def test_gil_disabled () -> None :
15+ """Assert that the GIL is disabled on free-threaded Python.
16+
17+ On free-threaded builds (3.13t, 3.14t, ...), the GIL should be disabled by default.
18+ If a C extension that hasn't declared ``Py_MOD_GIL_NOT_USED`` gets imported, the GIL
19+ is silently re-enabled and a ``RuntimeWarning`` is emitted. Combined with
20+ ``filterwarnings = ["error"]`` in our pytest config, this test ensures that no such
21+ extension has been loaded during the test session.
22+ """
23+ assert not sys ._is_gil_enabled (), (
24+ "The GIL has been re-enabled. A C extension that does not declare "
25+ "Py_MOD_GIL_NOT_USED was loaded during the test session."
26+ )
You can’t perform that action at this time.
0 commit comments