Skip to content

Commit 4f4091e

Browse files
committed
Fix for free-threaded Python tests
1 parent 006792b commit 4f4091e

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Our [PyPI wheels](https://pypi.org/project/libzim/) bundle a [recent release](ht
2929

3030
Wheels are available for CPython only (but can be built for Pypy).
3131

32+
Free-threaded CPython is not supported. If you use a free-threaded CPython, GIL must be turned on (using the environment variable PYTHON_GIL or the command-line option -X gil). If you don't turn it on yourself, GIL will be forced-on and you will get a warning. Only few methods support the GIL to be disabled.
33+
3234
Users on other platforms can install the source distribution (see [Building](#Building) below).
3335

3436

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ skip = "pp* *win32*"
123123
test-requires = ["pytest"]
124124
test-command = "py.test {project}/tests/"
125125

126+
# Override test command for free-threaded builds to force GIL on
127+
[[tool.cibuildwheel.overrides]]
128+
select = "cp313t-* cp314t-*"
129+
test-command = "python -X gil=1 -m pytest {project}/tests/"
130+
126131
manylinux-x86_64-image = "manylinux_2_28"
127132
manylinux-aarch64-image = "manylinux_2_28"
128133
manylinux-pypy_x86_64-image = "manylinux_2_28"

tests/test_libzim_creator.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,20 @@ def get_creator_output(fpath, verbose):
162162
).replace(
163163
"{verbose}", str(verbose)
164164
)
165+
166+
# Build command with appropriate GIL settings for free-threaded Python
167+
cmd = [sys.executable]
168+
169+
# Check if we're running in free-threaded mode (Python 3.13+)
170+
if sys.version_info >= (3, 13) and hasattr(sys, "_is_gil_enabled"):
171+
# If GIL is enabled, explicitly pass -X gil=1 to subprocess
172+
if sys._is_gil_enabled():
173+
cmd.extend(["-X", "gil=1"])
174+
175+
cmd.extend(["-c", code])
176+
165177
ps = subprocess.run(
166-
[sys.executable, "-c", code],
178+
cmd,
167179
stdout=subprocess.PIPE,
168180
stderr=subprocess.STDOUT,
169181
text=True,

0 commit comments

Comments
 (0)