Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/QA.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: QA
on: [push]
on:
pull_request:
push:
branches:
- main

env:
LIBZIM_DL_VERSION: "9.8.2-1"
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/Tests.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Tests
on: [push]
on:
pull_request:
push:
branches:
- main

env:
LIBZIM_DL_VERSION: "9.8.2-1"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Declare the extension free-threading compatible so that importing it on a free-threaded CPython no longer forces the GIL back on (#240)

## [3.13.1] - 2026-10-05

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Our [PyPI wheels](https://pypi.org/project/libzim/) bundle a [recent release](ht

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

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.
Free-threaded CPython is supported: the extension declares itself free-threading compatible, so importing it no longer forces the GIL back on. Only few methods support the GIL to be disabled; you must still prevent concurrent access to shared objects yourself (see [Thread safety](#thread-safety)).

Users on other platforms can install the source distribution (see [Building](#Building) below).

Expand Down
2 changes: 2 additions & 0 deletions libzim/libzim.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# cython: freethreading_compatible = True

# Make our libzim module a package by setting a __path__
# There is no real path here, but it will be passed to our module finder.
"""openZIM's file format library binding
Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ skip = "pp* *win32*"
test-requires = ["pytest"]
test-command = "py.test {project}/tests/"

# Override test command for free-threaded builds to force GIL on
[[tool.cibuildwheel.overrides]]
select = "cp313t-* cp314t-*"
test-command = "python -X gil=1 -m pytest {project}/tests/"

manylinux-x86_64-image = "manylinux_2_28"
manylinux-aarch64-image = "manylinux_2_28"
manylinux-pypy_x86_64-image = "manylinux_2_28"
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ def get_cython_extension() -> list[Extension]:
define_macros: list[tuple[str, str | None]] = []
compiler_directives = {"language_level": "3"}

if getattr(sys, "_is_gil_enabled", None) is not None and not sys._is_gil_enabled():
define_macros.append(("Py_GIL_DISABLED", "1"))

if config.profiling:
define_macros += [
("CYTHON_TRACE", "1"),
Expand Down
11 changes: 1 addition & 10 deletions tests/test_libzim_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,7 @@ def get_creator_output(fpath, verbose):
pass
""".replace("{fpath}", str(fpath)).replace("{verbose}", str(verbose))

# Build command with appropriate GIL settings for free-threaded Python
cmd = [sys.executable]

# Check if we're running in free-threaded mode (Python 3.13+)
if sys.version_info >= (3, 13) and hasattr(sys, "_is_gil_enabled"):
# If GIL is enabled, explicitly pass -X gil=1 to subprocess
if sys._is_gil_enabled():
cmd.extend(["-X", "gil=1"])

cmd.extend(["-c", code])
cmd = [sys.executable, "-c", code]

ps = subprocess.run(
cmd,
Expand Down
Loading