Skip to content

Make OpenFile filelike #1024

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

Merged
merged 2 commits into from
Aug 30, 2022
Merged

Conversation

martindurant
Copy link
Member

@martindurant martindurant commented Aug 16, 2022

@rabernat : a pickleable OpenFile in-a-context looks something like this, see what you think. Now entering with returns the OpenFile itself, which is now really file-like. It exists so that a chain of file-likes (compression, text...) can be closed in sequence at the right time. None of this affects what you get when you do a fs.open(), which objects are often pickleable (http, s3, local...), but this is not guaranteed.

Note that it breaks a couple of previous pickle tests, I will need to see whether the assumptions there are valid or not. Particularly, what should it mean to unpickle a "w"-mode file - naively, a new file gets opened with mode "w", invalidating the previous copy and truncating the file.

@rabernat
Copy link
Contributor

Thanks a lot for working on this Martin!

I'm not sure that the with context manager behavior is relevant for Pangeo Forge and pangeo-forge/pangeo-forge-recipes#391 (comment). The conclusion we reached in #579 (comment) (see also google/xarray-beam#49 (comment)) was that, in order to achieve the desired serializability, we should NOT use a context manager. Consequently, you will find no context managers in the Pangeo Forge file opener code, but rather just fs.open() style.

@martindurant
Copy link
Member Author

This change removes OpenFile.open.<locals>.close, which was used for pickling, and is a consequence of calling OpenFile.open (as opposed to filesystem.open), and showed up in the error message, so probably it is fixed here.

@martindurant martindurant merged commit 1e852ac into fsspec:master Aug 30, 2022
@martindurant martindurant deleted the open_file_open branch August 30, 2022 16:56
martindurant added a commit that referenced this pull request Aug 31, 2022
* Revert @1024

* fixes

* More OpenFiles lost

* remove test
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.

2 participants