Skip to content

Commit ffa7700

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 3b6b903 commit ffa7700

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

4647
0.24.0 (released 2025-08-17)
4748
============================

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)