Open
Avoid closed/locked HDF5 handles when lazily loading OMX matrices#83
Conversation
Copilot
AI
changed the title
[WIP] Fix ClosedNodeError on from_omx_3d
Avoid closed/locked HDF5 handles when lazily loading OMX matrices
Jul 30, 2026
jpn--
marked this pull request as ready for review
July 30, 2026 16:55
jpn--
approved these changes
Jul 30, 2026
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.
Datasets built by
from_omx_3dhold lazy dask arrays that reference the source HDF5 file. Computing them later (e.g.to_zarr) can fail withClosedNodeErrorwhen the array wraps a PyTables node whose handle is already closed, or withBlockingIOError(unable to lock file) when the reader tries to reopen a file the caller has open in write/append mode.Changes
_is_reopenable(filename)(new,sharrow/dataset.py): probes whether the underlying file can be independently opened read-only with h5py. ReturnsFalsefor unknown/in-memory filenames and for files locked by another open handle.from_omx_3d: uses the deferred reopen-based reader only for reopenable files; otherwise materializes the matrix eagerly (np.asarray(node[:])) instead of wrapping a live file node, so the dataset no longer depends on a handle staying open past graph construction. Reopenability is evaluated once per source file.from_omx: the 2D fast path now gates on_is_reopenable(filename)rather thanfilename is not None, falling back to reading through the caller's handle when reopening would fail.test_from_omx_3d_to_zarrcovers the reported scenario;test_from_omx_3d_writable_handlecovers compute from a handle opened in append mode (fails on the base commit with the lock error).Note the tradeoff: for non-reopenable sources, data is now read at dataset-construction time rather than lazily. That is the only way to keep the result valid after the handle closes, and it matches the existing eager behavior of
from_omx.ClosedNodeErroronfrom_omx_3d(path, ...)#79