Skip to content

Commit 32a31f8

Browse files
committed
ext: declare GIL as not used
Without this, the GIL is enabled when loading the extension module since we don't declare nogil compatibility. Let's allow loading without the GIL so we can start meaningfully testing running without the GIL. We still don't formally support free-threaded interpreters. But we do introduce the trove classifier at level 1 to indicate the feature is available.
1 parent 9f0ba62 commit 32a31f8

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

c-ext/backend_c.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ void decompressoriterator_module_init(PyObject *mod);
134134
void frameparams_module_init(PyObject *mod);
135135

136136
void zstd_module_init(PyObject *m) {
137+
#ifdef Py_GIL_DISABLED
138+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
139+
#endif
140+
137141
/* python-zstandard relies on unstable zstd C API features. This means
138142
that changes in zstd may break expectations in python-zstandard.
139143

docs/news.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Version History
4848
the 2.0 release. (#274)
4949
* Added CI coverage for free-threaded CPython 3.13 and 3.14. We do not yet
5050
formally support free-threaded builds. (#276)
51+
* The C and Rust backends now declare the GIL as unused.
5152

5253
0.24.0 (released 2025-08-17)
5354
============================

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ classifiers = [
1818
"Programming Language :: Python :: 3.12",
1919
"Programming Language :: Python :: 3.13",
2020
"Programming Language :: Python :: 3.14",
21+
"Programming Language :: Python :: Free Threading :: 1 - Unstable",
2122
]
2223
keywords = ["zstandard", "zstd", "compression"]
2324
dependencies = []

rust-ext/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use exceptions::ZstdError;
3434
// and debian/changelog as well.
3535
const VERSION: &'static str = "0.25.0.dev0";
3636

37-
#[pymodule]
37+
#[pymodule(gil_used = false)]
3838
fn backend_rust(py: Python, module: &Bound<'_, PyModule>) -> PyResult<()> {
3939
let features = PySet::new(
4040
py,

0 commit comments

Comments
 (0)