Thomas Kluyver added the comment:

For reference, we added our own atomic_writing() context manager in 
Jupyter/IPython, after someone lost work when save failed on a full disk. We 
initially went for the same approach - write to a temporary file, fsync, rename 
over the original file - but it caused issues with network filesystems and 
folders synced by Dropbox or similar services.

As a result we switched to an approach that copies the old file to a temporary 
name, writes the new data directly to the old name, then removes the temporary 
copy on success, or renames it back to the old name on failure. This is 
certainly less rigorous, but it means that we're not replacing the file on 
every save, and it's less of a problem if copying file attributes with 
copystat() fails.

I'm sure there are use cases for atomic writing where these problems won't come 
up, but I hope this is a useful data point, at least for documenting any atomic 
writing solution.

----------
nosy: +takluyver

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8604>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to