Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80019

Re: Saving a file "in the background" -- How?

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'repository': 0.05; 'startup': 0.05; 'subsequent': 0.05; 'automate': 0.07; 'detect': 0.07; 'postgresql': 0.07; 'subject:file': 0.07; 'assuming': 0.09; 'git': 0.09; 'level:': 0.09; 'postgres': 0.09; 'restart': 0.09; 'whichever': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'autosave': 0.16; 'else"': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'headaches': 0.16; 'incomplete': 0.16; 'personally,': 0.16; 'reliably': 0.16; 'saved,': 0.16; 'files.': 0.16; 'sat,': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'commit': 0.19; 'file,': 0.19; 'server,': 0.19; 'not,': 0.20; 'manual': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'file.': 0.24; 'looks': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'handling': 0.26; 'push': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'ideal': 0.29; 'points': 0.29; "doesn't": 0.30; 'database,': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'work.': 0.31; 'program,': 0.31; 'that.': 0.31; 'usually': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'though.': 0.31; 'trivial': 0.31; 'with,': 0.31; 'text': 0.33; 'cases': 0.33; 'trouble': 0.34; 'maybe': 0.34; 'subject:the': 0.34; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'problem.': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'done': 0.36; 'subject:?': 0.36; 'level': 0.37; 'remote': 0.38; 'server': 0.38; 'nov': 0.38; 'handle': 0.38; 'previous': 0.38; 'rather': 0.38; 'does': 0.39; 'delete': 0.39; 'either': 0.39; 'how': 0.40; 'failures': 0.60; 'then,': 0.60; 'worry': 0.60; 'most': 0.60; 'hope': 0.61; 'lower': 0.61; 'back': 0.62; 'save': 0.62; 'complete': 0.62; 'more': 0.64; 'great': 0.65; 'temporary': 0.65; 'power': 0.76; '250mb': 0.84; 'partial': 0.84; 'reliability': 0.84; '"how': 0.91; 'opens': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=0fGMHMqb0FbbSDnsEW5+dO4N3LbH/vS3/yit91fkWjc=; b=slULnFEbTP7YUbX9SLFgx7Bi6mqQ1tCFbZ0nKQQrd1YipoGO60mfs5BA+mrYF+xxLX zTYBHL+LsfcVAqWCDxzt0N0wTD97hl1T0/mytmlqvo5cf9jb/7rbUEtB/kL/1NclHcL7 PyPn8wuE/DdECdyK7gDm3h9aSKoTwaROlWtnZ8JK6l5Zf2xKxe+dHmPwytk9iBng03BU ML2UZGxVpHm8ZObjGeKbJxyXi5W5K9nci13+jtrvBmGoxwjaoK09ERHtIFQsmL3FGTZE 1CzLIiUW27v0ErunylaE68CjqgQXlluxv/YmG8l7RyeK3+lmYQSnVTRz6t4oh0fUXVcp QbZg==
MIME-Version 1.0
X-Received by 10.50.128.35 with SMTP id nl3mr4645552igb.34.1414765794432; Fri, 31 Oct 2014 07:29:54 -0700 (PDT)
In-Reply-To <54539760$0$13009$c3e8da3$5496439d@news.astraweb.com>
References <5452ADFD.5030801@it.uu.se> <87h9ykphm9.fsf@gmail.com> <mailman.15352.1414757973.18130.python-list@python.org> <54539760$0$13009$c3e8da3$5496439d@news.astraweb.com>
Date Sat, 1 Nov 2014 01:29:54 +1100
Subject Re: Saving a file "in the background" -- How?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15357.1414765802.18130.python-list@python.org> (permalink)
Lines 53
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414765802 news.xs4all.nl 2850 [2001:888:2000:d::a6]:54458
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80019

Show key headers only | View raw


On Sat, Nov 1, 2014 at 1:06 AM, Steven D'Aprano
<steve+comp.lang.python@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
>> server,
>
> 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.

ChrisA

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: Saving a file "in the background" -- How? Chris Angelico <rosuav@gmail.com> - 2014-10-31 23:19 +1100
  Re: Saving a file "in the background" -- How? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-01 01:06 +1100
    Re: Saving a file "in the background" -- How? Chris Angelico <rosuav@gmail.com> - 2014-11-01 01:29 +1100

csiph-web