Re: How to safely maintain a status file

Discussion in 'Python' started by Dennis Lee Bieber, Jul 8, 2012.

  1. On Sun, 8 Jul 2012 21:29:41 +1000, Richard Baron Penman
    <> 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://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Jul 8, 2012
    #1
    1. Advertising

  2. Dennis Lee Bieber

    Plumo Guest

    > > 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.
     
    Plumo, Jul 9, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Baron Penman

    How to safely maintain a status file

    Richard Baron Penman, Jul 8, 2012, in forum: Python
    Replies:
    0
    Views:
    205
    Richard Baron Penman
    Jul 8, 2012
  2. Laszlo Nagy

    Re: How to safely maintain a status file

    Laszlo Nagy, Jul 8, 2012, in forum: Python
    Replies:
    1
    Views:
    236
    Nobody
    Jul 9, 2012
  3. Plumo
    Replies:
    1
    Views:
    218
    Michael Hrivnak
    Jul 9, 2012
  4. Plumo
    Replies:
    1
    Views:
    216
    Laszlo Nagy
    Jul 12, 2012
  5. John Nagle
    Replies:
    2
    Views:
    323
    Laszlo Nagy
    Jul 12, 2012
Loading...

Share This Page