Make test_chunks_is_lazy counter thread-safe for the free-threaded CI lane#3364
Merged
Conversation
) The 3.14t full-suite job fails on test_chunks_is_lazy_does_not_call_internal_reader with 'expected 16 per-chunk decodes after compute, got 15'. compute() runs the 16 per-chunk reads through dask's threaded scheduler; under PYTHON_GIL=0 the bare counter['calls'] += 1 in the counting wrapper races and loses an update, so 16 real decodes count as 15. Guard the increment with a threading.Lock. Test-instrumentation fix only; the chunked decode already runs 16 times correctly.
brendancol
commented
Jun 16, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
PR Review: thread-safe counter for test_chunks_is_lazy
Test-only change, one file. The diagnosis and fix are right: compute() fans the 16 per-chunk reads across dask's threaded scheduler, and under PYTHON_GIL=0 the bare counter['calls'] += 1 is a racing read-modify-write that drops an update. A threading.Lock around the increment makes the count exact. No blockers.
Blockers
- None.
Suggestions
- None. The lock scope is minimal (wraps only the increment, not
real_read), so it adds no contention on the actual decode and doesn't perturb timing.
Nits
- None.
What looks good
- The lazy assertion (
counter['calls'] == 0beforecompute()) is unaffected —counting_readisn't called until compute, so the pre-compute count stays 0. - Correctly scoped: confirmed the other counter-based tests (
test_metadata.py,test_overview.py,test_visibility.py) assert a single non-concurrent call (== 1), which can't lose an update, so they don't need the same guard. - Import added in stdlib alphabetical order; flake8 clean.
- Product code untouched — the chunked decode already runs 16 times and returns correct data; this only fixes the instrumentation.
Checklist
- Root cause correct (non-atomic counter under free-threading)
- Fix is minimal and thread-safe
- Pre-compute lazy assertion preserved
- No product code touched
- Scope verified against sibling counter tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3363
The
3.14tfull-suite job onmainfails on one test:result.compute()runs the 16 per-chunk reads through dask's threaded scheduler. UnderPYTHON_GIL=0(the3.14tpytest step) those run truly in parallel, and the counting wrapper'scounter['calls'] += 1is a non-atomic read-modify-write that loses an update, so 16 real decodes count as 15.threading.Lockso the count is exact under both the GIL and the free-threaded interpreter.== 1) and can't lose an update.Surfaced by the
3.14tlane (#3360). That job is allowed-failure, somainstill concludes success, but this clears the red.Test plan:
pytest xrspatial/geotiff/tests/vrt/test_window.pypasses under the GIL (no regression).3.14tfull lane goes green.