Saving a file "in the background" -- How?
rosuav at gmail.com
Fri Oct 31 15:29:54 CET 2014
On Sat, Nov 1, 2014 at 1:06 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Chris Angelico wrote:
>> Sounds like a lot of hassle, and a lot of things that could be done
>> wrongly. Personally, if I need that level of reliability and
>> atomicity, I'd rather push the whole question down to a lower level:
>> maybe commit something to a git repository and push it to a remote
> How is pushing something to a remote server more reliable than writing to a
> local drive?
It's not, as far as the program's concerned, but when I need
reliability I usually also need replication/backups.
>> or use a PostgreSQL database, or something of that sort. Let
>> someone else have the headaches about "what if AV opens the file". Let
>> someone else worry about how to cope with power failures at arbitrary
>> points in the code.
> That "someone else" is still you though. And "use a PostgreSQL database" is
> no solution to the problem "how do I reliably write a 250MB video file?".
If the commit happens, it's saved, and everything else isn't my
problem. And yes, Postgres isn't ideal for a 250MB file, but then,
neither is any sort of autosave good for that. I'm assuming the
content isn't that big.
> Or for that matter, a 2KB text file. Databases are great as databases, but
> they aren't files.
A database can handle a 2KB text file, no problem. That's how most CMSes work.
>> (Though, to be fair, using git for this doesn't
>> fully automate failure handling; what it does is allow you to detect
>> issues on startup, and either roll back ("git checkout -f") or apply
>> ("git commit -a") if it looks okay.)
> I don't see how this sort of manual handling is less trouble than using a
> proper, reliable save routine. To start with, what do you mean "detect
> issues on startup" -- startup of what?
Because fundamentally it's impossible to write a reliable save
routine. The best you can do is detect, on subsequent restart of your
program, that there was an incomplete save in a previous session, and
either roll it back or complete it. In some cases that's trivial - if
there's a temporary file, you have the partial save, so you delete the
temporary (rolling back) - or you just ignore it and overwrite, and
hope that it's not going to get stuck anywhere. But it's still the
same broad technique, whichever way you do it.
More information about the Python-list