20

I am wondering whether python's shutil.move is atomic on linux ? Is the behavior different if the source and destination files are on two different partitions or is it same as when they are present on the same partition ?

I am more concerned to know whether the shutil.move is atomic if the source and destination files are on the same partition !

SilentGhost
  • 307,395
  • 66
  • 306
  • 293
Kisalay
  • 607
  • 1
  • 6
  • 11
  • Did you read the source? It's available in your Python library on your computer. What did you see in the `shutil` module? – S.Lott Sep 15 '10 at 10:08

1 Answers1

22

It is not atomic if the files are on different filsystems. In that case, python opens the source and destination file, loops on reading from the source and writing to the desination and finally unlinks the source file.

If the source and destination file are on the same file system, python uses the rename() C call, which is atomic.

nos
  • 223,662
  • 58
  • 417
  • 506