How to safely maintain a status file

Plumo richardbp at gmail.com
Mon Jul 9 01:50:05 EDT 2012


> 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.



More information about the Python-list mailing list