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 pickling FileAccess objects with cloudpickle #303

Merged
merged 2 commits into from Apr 6, 2022

Conversation

takluyver
Copy link
Member

cloudpickle is an extended Pickle library used by projects like Dask and clusterfutures to send objects around. @tmichela found that it wasn't working with EXtra-data 1.10, probably because of #264.

The issue was the FileAccess._from_pickle classmethod. cloudpickle attempted to save this 'by value', and since it uses the file access registry, it tried to pickle the registry as well, and it can't handle the weakref objects stored there. The best option I can see is to make it a staticmethod instead (i.e. a plain function defined in a class), which cloudpickle pickles 'by reference' - i.e. it stores the path to import and look up the function in the destination.

This would make subclassing FileAccess a bit more work, but I'm not aware of anyone doing that, and I wouldn't encourage it - subclasses are quite likely to break when details change.

@takluyver takluyver added the bug Something isn't working label Apr 6, 2022
@takluyver takluyver added this to the 1.12 milestone Apr 6, 2022
@takluyver takluyver requested a review from tmichela April 6, 2022 09:39
@tmichela
Copy link
Member

tmichela commented Apr 6, 2022

Thanks! LGTM

@takluyver takluyver merged commit 1e50e05 into master Apr 6, 2022
@takluyver takluyver deleted the fileaccess-cloudpickle branch April 6, 2022 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants