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

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

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.
 
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 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
Re: How to safely maintain a status file Dennis Lee Bieber Python 1 07-09-2012 05:58 AM
How to safely maintain a status file Richard Baron Penman Python 0 07-08-2012 11:29 AM



Advertisments