From 173de3e0d20407a358e9af00140f0744f0e68e57 Mon Sep 17 00:00:00 2001 From: osobh Date: Sun, 27 Sep 2026 07:48:04 -0500 Subject: [PATCH] py: test that an edit releases the GIL A thread appending timestamps in a loop runs while a 1024x1024 gzip dataset is rewritten through 'r+': the largest gap between its stamps during the edit must be under half the edit's duration (an edit holding the GIL stalls it for the whole edit; checked with a GIL-holding regex standing in for the edit: one 0.20 s gap in a 0.21 s call). Edits already ran detached; nothing tested it. Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/clawhdf5-py/tests/test_edit.py | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/crates/clawhdf5-py/tests/test_edit.py b/crates/clawhdf5-py/tests/test_edit.py index c0b7ba6..ac28607 100644 --- a/crates/clawhdf5-py/tests/test_edit.py +++ b/crates/clawhdf5-py/tests/test_edit.py @@ -896,3 +896,38 @@ def test_path_replaced_between_edits(h5py, tmp_path): from pathlib import Path _held_file_edited(h5py, moved, Path(path), other_bytes) + +def test_an_edit_releases_the_gil(h5py, tmp_path): + """Another Python thread keeps running while a large edit is written: + had the edit held the GIL, the other thread would stall for the whole + edit (Rust code never yields it).""" + import time + path = str(tmp_path / "big.h5") + with h5py.File(path, "w") as f: + f.create_dataset("d", shape=(1024, 1024), dtype=" 0.1, "the edit is too quick to tell" + assert gaps.max() < 0.5 * (t1 - t0), ( + f"the other thread stalled for {gaps.max():.3f} s of a {t1 - t0:.3f} s edit")