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

OSError: [Errno 18] Invalid cross-device link error on readthedocs #322

Closed
gmaze opened this issue Jun 17, 2020 · 5 comments · Fixed by #323
Closed

OSError: [Errno 18] Invalid cross-device link error on readthedocs #322

gmaze opened this issue Jun 17, 2020 · 5 comments · Fixed by #323

Comments

@gmaze
Copy link

gmaze commented Jun 17, 2020

Hi folks,
I develop a python library to work with ocean data collected using a specific type of instruments (Argo floats): https://github.com/euroargodev/argopy
Data can be fetched from local files or from an erddap server online.

I recently tried to use fsspec to implement file/resource management and ease handling of cached data.
I ended up wrapping file, memory and http fsspec file systems into classes that managed custom methods like open_dataset or open_dataframe.

I worked nicely up to the point where the new master branch was pushed to readthedocs, which failed because of a:

OSError: [Errno 18] Invalid cross-device link: '/tmp/tmp1twhthrp' -> 'mycache_folder/cache'

The error is raised when readthedocs executes a notebook where I demonstrate the use of the caching system of argopy.
The error is raised by the sspec/implementations/cached.py save_cache(self) method in the line where the new cache replace the old one: os.replace(fn2, fn).

This is apparently raised because os expect files to be from the same file system.

Is this only related to readthedocs ? and if you have any ideas about how to fix this, that would be great ! One possibility is by using shutil.move instead of os.rename.

The RTD log build with the error can be seen here.
The interesting peace is here (sorry for the RTD character mess):

�[0;32m~/checkouts/readthedocs.org/user_builds/argopy/envs/latest/lib/python3.6/site-packages/fsspec/implementations/cached.py�[0m in �[0;36msave_cache�[0;34m(self)�[0m
�[1;32m    157�[0m         �[0;32mwith�[0m �[0mopen�[0m�[0;34m(�[0m�[0mfn2�[0m�[0;34m,�[0m �[0;34m"wb"�[0m�[0;34m)�[0m �[0;32mas�[0m �[0mf�[0m�[0;34m:�[0m�[0;34m�[0m�[0;34m�[0m�[0m
�[1;32m    158�[0m             �[0mpickle�[0m�[0;34m.�[0m�[0mdump�[0m�[0;34m(�[0m�[0mcache�[0m�[0;34m,�[0m �[0mf�[0m�[0;34m)�[0m�[0;34m�[0m�[0;34m�[0m�[0m
�[0;32m--> 159�[0;31m         �[0mos�[0m�[0;34m.�[0m�[0mreplace�[0m�[0;34m(�[0m�[0mfn2�[0m�[0;34m,�[0m �[0mfn�[0m�[0;34m)�[0m�[0;34m�[0m�[0;34m�[0m�[0m
�[0m�[1;32m    160�[0m �[0;34m�[0m�[0m
�[1;32m    161�[0m     �[0;32mdef�[0m �[0m_check_cache�[0m�[0;34m(�[0m�[0mself�[0m�[0;34m)�[0m�[0;34m:�[0m�[0;34m�[0m�[0;34m�[0m�[0m

�[0;31mOSError�[0m: [Errno 18] Invalid cross-device link: '/tmp/tmp3wnrdtiz' -> 'mycache_folder/cache'
OSError: [Errno 18] Invalid cross-device link: '/tmp/tmp3wnrdtiz' -> 'mycache_folder/cache'
@martindurant
Copy link
Member

One possibility is by using shutil.move instead of os.rename

This is probably the right answer. I was trying to ameliorate the effect or races, since it's possible that multiple instances are accessing the cache from multiple threads or processes, but it ought to be the case that the worst result is that occasionally a file is downloaded more than once.

Note that you may want to use "simplecache" instead, if you don't expect your files to ever expire or change on the remote server. simplecache does not maintain any metadata, so does not suffer this problem.

@martindurant
Copy link
Member

(actually, shutil.move calls os.rename when possible anyway)

@gmaze
Copy link
Author

gmaze commented Jun 17, 2020

I think I need the full cache meta data, since I have some expiration dates to enforce.

To use shutil.move, would it be a simple change in cached.py ?
In this case I can try a PR with this...

@martindurant
Copy link
Member

PR here: #323
(I am not adding a test that would fail os.replace, I'm not sure how that could be done on TravisCI)

@gmaze
Copy link
Author

gmaze commented Jun 17, 2020

awesome !
thanks for being so quick !

gmaze added a commit to euroargodev/argopy that referenced this issue Jun 17, 2020
Removed all cells executions because of the fsspec issue with links at readthedocs (see [here](fsspec/filesystem_spec#322))
hamersu9t added a commit to hamersu9t/argopy that referenced this issue Aug 10, 2024
Removed all cells executions because of the fsspec issue with links at readthedocs (see [here](fsspec/filesystem_spec#322))
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 a pull request may close this issue.

2 participants