def atomic_rename(oldpath, newpath):
 if iswindows:
  import win32file
  for i in xrange(10):
   try:
    win32file.MoveFileEx(oldpath, newpath, (win32file.MOVEFILE_REPLACE_EXISTING | win32file.MOVEFILE_WRITE_THROUGH))
    break
   except Exception:
    if (i > 8):
     raise
    time.sleep(1)
 else:
  os.rename(oldpath, newpath)

def atomic_rename ( oldpath , newpath ) : if iswindows : import win32file for i in xrange ( 10 ) : try : win32file . MoveFileEx ( oldpath , newpath , ( win32file . MOVEFILE_REPLACE_EXISTING | win32file . MOVEFILE_WRITE_THROUGH ) ) break except Exception : if ( i > 8 ) : raise time . sleep ( 1 ) else : os . rename ( oldpath , newpath )
replace the file newpath with the file oldpath .