Conversation
dcherian
approved these changes
Sep 30, 2026
5 tasks done
ScipyArrayWrapper copied data from memory mapped files only after releasing the file, so another dask thread could evict and close the file while a view into its memory map was still alive. scipy then warns "Cannot close a netcdf_file opened with mmap=True" and leaves the mmap open. Read and copy inside acquire_context() instead, which keeps the file open until the copy is done. Also silence the expected unclosed-file warning in test_file_manager_del_while_pin_lock_held. Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
Guards against keeping a reference into the memory map alive while the file is unpinned, which makes scipy warn and leave the mmap open. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
headtr1ck
force-pushed
the
fix-scipy-mmap-eviction
branch
from
September 30, 2026 15:38
b167878 to
ffe67cc
Compare
headtr1ck
enabled auto-merge (squash)
September 30, 2026 15:39
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.
Description
Fixes the
RuntimeWarning: Cannot close a netcdf_file opened with mmap=True, when netcdf_variables or arrays referring to its data still existwarnings intest_open_mfdataset_manyfiles[scipy-20-...-5].ScipyArrayWrapper._getitemreturned a view into the memory map and__getitem__only copied it afterwards, when the file was no longer held. When reading with dask threads and more files thanfile_cache_maxsize, another thread could evict and close the file while that view was still alive. scipy then warns and leaves the mmap open.The data is now read and copied inside
_manager.acquire_context(), which pins the file until the copy is done (the pinning from #11622). As a side effect, the numpy < 2copy=workaround is gone and__getitem__no longer re-acquires the file just to checkuse_mmap.Also silences the expected unclosed-file
RuntimeWarningintest_file_manager_del_while_pin_lock_held, which deliberately deallocates an unclosed manager (the test suite turns onwarn_for_unclosed_filesglobally).No regression test: the warning is raised in a dask worker thread, so turning it into an error with
filterwarningsdoesn't fail the test.Checklist
whats-new.rstAI Disclosure
Tools: Claude Code (Claude Opus 5.5)
Prompt: "can we fix these warnings?" (pasting the
PytestUnraisableExceptionWarningfromtest_file_manager_del_while_pin_lock_heldand the scipy mmapRuntimeWarnings fromtest_open_mfdataset_manyfiles)[This is Claude Code on behalf of Michael Niklas]
🤖 Generated with Claude Code