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


Groups > comp.lang.python > #25051

Re: How to safely maintain a status file

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: How to safely maintain a status file
Date 2012-07-08 15:35 -0400
Organization > Bestiaria Support Staff <
References <CAOV1wRVtm27yWez1HZuN8=ia-TyM2aXp9QCUbSZ5aZExP_ZChA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1925.1341776139.4697.python-list@python.org> (permalink)

Show all headers | View raw


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/

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


Thread

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

csiph-web