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


Groups > comp.lang.python > #25051 > unrolled thread

Re: How to safely maintain a status file

Started byDennis Lee Bieber <wlfraed@ix.netcom.com>
First post2012-07-08 15:35 -0400
Last post2012-07-08 22:58 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to safely maintain a status file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-08 15:35 -0400
    Re: How to safely maintain a status file Plumo <richardbp@gmail.com> - 2012-07-08 22:58 -0700

#25051 — Re: How to safely maintain a status file

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2012-07-08 15:35 -0400
SubjectRe: How to safely maintain a status file
Message-ID<mailman.1925.1341776139.4697.python-list@python.org>
On Sun, 8 Jul 2012 21:29:41 +1000, Richard Baron Penman
<richardbp@gmail.com> declaimed the following in
gmane.comp.python.general:


> and then on startup read from tmp_file if status_file does not exist.
> But this seems awkward.
>
	It also violates your requirement -- since the "crash" could take
place with a partial "temp file".

	I'd suggest that, rather than deleting the old status file, you
rename IT -- and only delete it IF you successfully rename the temp
file.

#pseudo code -- initialization
if exists("old-status.file"):
	#assume system crashed
	if exists("status.file"):
		delete("status.file")
		rename("old-status.file", "status.file")
	
if exists("status.file"):
	read("status.file")
	rename("status.file", "old-status.file")
else:
	#start-up with no status history

# -- snapshot
if exists("status.file"):
	if exists("old-status.file"):
		delete("old-status.file")
	rename("status.file", "old-status.file")
write("temp.file", "snapshot-data")
rename("temp.file", "status.file")
delete("old-status.file")
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [next] | [standalone]


#25065

FromPlumo <richardbp@gmail.com>
Date2012-07-08 22:58 -0700
Message-ID<f5d2ed89-3457-4b7c-9dbc-cfae847a041a@vb9g2000pbc.googlegroups.com>
In reply to#25051
> > and then on startup read from tmp_file if status_file does not exist.
> > But this seems awkward.
>
>         It also violates your requirement -- since the "crash" could take
> place with a partial "temp file".

Can you explain why?
My thinking was if crash took place when writing the temp file this
would not matter because the status file would still exist and be read
from. The temp file would only be renamed when fully written.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web