Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fsspec closure checks #1333

Merged
merged 3 commits into from
Nov 12, 2024
Merged

fix: fsspec closure checks #1333

merged 3 commits into from
Nov 12, 2024

Conversation

ariostas
Copy link
Collaborator

@ariostas ariostas commented Nov 7, 2024

This PR fixes #1292.

I fixed the closed property of FSSpecSource so that it doesn't always return False. I asked Luis about this, and here's my current understanding. This property was added so that it didn't just use the inherited property from Source since it wouldn't work for custom executors.

@property
def closed(self) -> bool:
"""
True if the associated file/connection/thread pool is closed; False
otherwise.
"""
if self._executor is None:
return True
return self._executor.closed

However, we can simply use the closed property of _file as shown in the changes below. I'm tagging @lobis to see if he has any concerns about this.

I also changed the chunk(s) methods to perform a closure check before reading. So now the example in #1292 fails.

>>> import uproot
>>> import skhep_testdata
>>> with uproot.open(skhep_testdata.data_path("uproot-Zmumu.root")) as file:
...     tree = file["events"]
...     
>>> tree["px1"].array()
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    tree["px1"].array()
    ~~~~~~~~~~~~~~~~~^^
  File "/Users/ariostas/Documents/uprootWork/uproot5/src/uproot/behaviors/TBranch.py", line 1825, in array
    _ranges_or_baskets_to_arrays(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self,
        ^^^^^
    ...<9 lines>...
        interp_options,
        ^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/ariostas/Documents/uprootWork/uproot5/src/uproot/behaviors/TBranch.py", line 3026, in _ranges_or_baskets_to_arrays
    hasbranches._file.source.chunks(ranges, notifications=notifications)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ariostas/Documents/uprootWork/uproot5/src/uproot/source/fsspec.py", line 136, in chunks
    raise OSError(f"memmap is closed for file {self._file_path}")
OSError: memmap is closed for file /Users/ariostas/.local/skhepdata/uproot-Zmumu.root

@ariostas ariostas force-pushed the ariostas/fsspec_closure_checks branch from 86bf869 to 74a0558 Compare November 12, 2024 14:32
@ariostas ariostas requested a review from jpivarski November 12, 2024 14:33
Copy link
Member

@jpivarski jpivarski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is the right thing to do, but I think the text of the error message (below) was wrong. Unless you happen to know that it's really memmap, please change that.

src/uproot/source/fsspec.py Outdated Show resolved Hide resolved
@ariostas
Copy link
Collaborator Author

Thank you, @jpivarski! I fixed the error messages.

@jpivarski
Copy link
Member

This is a simple enough PR that I don't think you have any more changes coming, so I'll merge now. Thanks!

@jpivarski jpivarski merged commit 9568d90 into main Nov 12, 2024
26 checks passed
@jpivarski jpivarski deleted the ariostas/fsspec_closure_checks branch November 12, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fsspec Source (the local file one, at least) does not close files
2 participants