This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2010-05-26.23:41:40
SpamBayes Score 0.0043394146
Marked as misclassified No
Message-id <1274917301.93.0.503310941815.issue8828@psf.upfronthosting.co.za>
In-reply-to
Content
os.rename() is atomic on Linux, but on Windows it raises an error if the destination does already exist.

Not atomic pseudo-code for Windows:
  if exists(b):
     unlink(b)
  rename(a, b)

Windows offers different functions depending on the version:
 - MoveFileTransacted(): atomic! version >= (Windows Vista, Windows Server 2008)
 - ReplaceFile(): version >= Windows 2000
 - MoveFileEx() with MOVEFILE_REPLACE_EXISTING and MOVEFILE_WRITE_THROUGH flags: not atomic (eg. "If the file is to be moved to a different volume, the function simulates the move by using the CopyFile and DeleteFile functions."), version >= Windows 2000

I don't think that it's possible to write an atomic rename (file) function for any OS, so it's only a "best effort" atomic function. The documentation will give a list of OS on which the operation *is* atomic (eg. Linux).

Note: os.rename() uses MoveFileW() on Windows.
History
Date User Action Args
2010-05-26 23:41:42vstinnersetrecipients: + vstinner
2010-05-26 23:41:41vstinnersetmessageid: <1274917301.93.0.503310941815.issue8828@psf.upfronthosting.co.za>
2010-05-26 23:41:40vstinnerlinkissue8828 messages
2010-05-26 23:41:40vstinnercreate