Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How to safely maintain a status file

Reply
Thread Tools

Re: How to safely maintain a status file

 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      07-08-2012
On Sun, 8 Jul 2012 21:29:41 +1000, Richard Baron Penman
<(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) HTTP://wlfraed.home.netcom.com/

 
Reply With Quote
 
 
 
 
Plumo
Guest
Posts: n/a
 
      07-09-2012
> > 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to safely maintain a status file Plumo Python 1 07-12-2012 05:46 PM
Re: How to safely maintain a status file John Nagle Python 2 07-12-2012 12:31 PM
Re: How to safely maintain a status file Plumo Python 1 07-09-2012 08:47 PM
Re: How to safely maintain a status file Laszlo Nagy Python 1 07-09-2012 08:57 AM
How to safely maintain a status file Richard Baron Penman Python 0 07-08-2012 11:29 AM



Advertisments