[Python-ideas] `to_file()` method for strings

Steven D'Aprano steve at pearwood.info
Wed Mar 23 23:10:30 EDT 2016


On Wed, Mar 23, 2016 at 10:14:07AM -0700, Nathaniel Smith wrote:

> POSIX doesn't guarantee anything whatsoever over power loss. Individual
> filesystem implementations make somewhat stronger guarantees, but it's a
> mess:
>   http://danluu.com/file-consistency/
[...]
> I don't want to get sucked into a long debate about this; it's entirely
> likely that adding something like that original recipe to the stdlib would
> be an improvement, so long as it had *very* detailed docs explaining the
> exact tradeoffs made. All I want to do is raise a cautionary flag that such
> an effort would need to tread carefully :-)

And then there are file media which lie to you, and return from a fsync 
before actually syncing, because that makes their benchmarks look good. 
I've seen file corruption on USB sticks that do this, including some 
otherwise "respectable" brands. Worst case I ever saw was a USB stick 
that (fortunately) had a blinking light to show when it was writing. It 
continuing writing for *eight minutes* (I timed it) after returning from 
fsync and the OS had unmounted the stick and it was nominally safe to 
remove.

I'm told that some hard drives will do the same, although I've never 
knowingly seen it.



-- 
Steve


More information about the Python-ideas mailing list