Re: How to safely maintain a status file

Discussion in 'Python' started by Plumo, Jul 9, 2012.

  1. Plumo

    Plumo Guest

    > Windows doesn't suppport atomic renames if the right side exists.  I
    > suggest that you implement two code paths:
    >
    > if os.name == "posix":
    >     rename = os.rename
    > else:
    >     def rename(a, b):
    >         try:
    >             os.rename(a, b)
    >         except OSError, e:
    >             if e.errno != 183:
    >                 raise
    >             os.unlink(b)
    >             os.rename(a, b)



    Problem is if the process is stopped between unlink and rename there
    would no status file.
    Plumo, Jul 9, 2012
    #1
    1. Advertising

  2. Plumo

    Laszlo Nagy Guest


    >> Windows doesn't suppport atomic renames if the right side exists. I
    >> suggest that you implement two code paths:
    >>
    >> if os.name == "posix":
    >> rename = os.rename
    >> else:
    >> def rename(a, b):
    >> try:
    >> os.rename(a, b)
    >> except OSError, e:
    >> if e.errno != 183:
    >> raise
    >> os.unlink(b)
    >> os.rename(a, b)

    >
    > Problem is if the process is stopped between unlink and rename there
    > would no status file.

    Yes, and actually it does not need to be an abnormal termination. It is
    enough if the OS scheduler puts this process on hold for some time...

    But using a lock file, the problem can be solved. However in that case,
    reading a status file can be a blocking operation.
    Laszlo Nagy, Jul 12, 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:
    177
    Richard Baron Penman
    Jul 8, 2012
  2. Dennis Lee Bieber

    Re: How to safely maintain a status file

    Dennis Lee Bieber, Jul 8, 2012, in forum: Python
    Replies:
    1
    Views:
    168
    Plumo
    Jul 9, 2012
  3. Laszlo Nagy

    Re: How to safely maintain a status file

    Laszlo Nagy, Jul 8, 2012, in forum: Python
    Replies:
    1
    Views:
    205
    Nobody
    Jul 9, 2012
  4. Plumo
    Replies:
    1
    Views:
    193
    Michael Hrivnak
    Jul 9, 2012
  5. John Nagle
    Replies:
    2
    Views:
    300
    Laszlo Nagy
    Jul 12, 2012
Loading...

Share This Page