Skip to content

Commit 472a074

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.
1 parent 8842dd2 commit 472a074

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-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
@@ -32,6 +32,7 @@ Version History
3232
the 2.0 release. (#274)
3333
* Added CI coverage for free-threaded CPython 3.13 and 3.14. We do not yet
3434
formally support free-threaded builds. (#276)
35+
* The C and Rust backends now declare the GIL as unused.
3536

3637
0.24.0 (released 2025-08-17)
3738
============================

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)