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


Groups > comp.lang.python > #25073

Re: How to safely maintain a status file

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!zen.net.uk!dedekind.zen.co.uk!reader02.nrc01.news.zen.net.uk.POSTED!not-for-mail
From Nobody <nobody@nowhere.com>
Subject Re: How to safely maintain a status file
Date Mon, 09 Jul 2012 09:57:15 +0100
User-Agent Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.)
Message-Id <pan.2012.07.09.08.57.14.881000@nowhere.com>
Newsgroups comp.lang.python
References <CAOV1wRVtm27yWez1HZuN8=ia-TyM2aXp9QCUbSZ5aZExP_ZChA@mail.gmail.com> <sanjv7lo0vb3rlhip4ov1gpgp4gs51bvfr@invalid.netcom.com> <mailman.1926.1341781085.4697.python-list@python.org>
MIME-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Lines 22
Organization Zen Internet
NNTP-Posting-Host bb993de8.news.zen.co.uk
X-Trace DXC=jQOd@1;91lmDW6OfPQo7cc]G;bfYi23hd=dR0\ckLKG`WeZ<[7LZNRfYN[SBa\<hViNQ<`Sf8^TaoEa8k2mWUM=`m5L7^?ge[9d
X-Complaints-To abuse@zen.co.uk
Xref csiph.com comp.lang.python:25073

Show key headers only | View raw


On Sun, 08 Jul 2012 22:57:56 +0200, Laszlo Nagy wrote:

> Yes, this is much better. Almost perfect. Don't forget to consult your
> system documentation, and check if the rename operation is atomic or not.
> (Most probably it will only be atomic if the original and the renamed file
> are on the same physical partition and/or mount point).

On Unix, rename() is always atomic, and requires that source and
destination are on the same partition (if you want to "move" a file across
partitions, you have to copy it then delete the original).

> But even if the rename operation is atomic, there is still a race
> condition. Your program can be terminated after the original status file
> has been deleted, and before the temp file was renamed. In this case, you
> will be missing the status file (although your program already did
> something just it could not write out the new status).

In the event of abnormal termination, losing some data is to be expected.
The idea is to only lose the most recent data while keeping the old copy,
rather than losing everything. Writing to a temp file then rename()ing
achieves that.

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


Thread

Re: How to safely maintain a status file Laszlo Nagy <gandalf@shopzeus.com> - 2012-07-08 22:57 +0200
  Re: How to safely maintain a status file Nobody <nobody@nowhere.com> - 2012-07-09 09:57 +0100

csiph-web