1

According to the documentation of the open function in os, which I assume is analogous to the high level open function in terms of file access modes, the behaviour of the O_EXCL flag depends on the underlying operating system, and links to documentation for Linux and Windows. Evidence that 'x' mode is equivalent to O_EXCL|O_CREAT can be seen from the GitHub repo of Python's C code.

The Linux page says O_EXCL is atomic, but the Windows page doesn't mention anything about atomicity.

Can any one give evidence that the 'x' mode is indeed atomic under Windows such that there cannot be a race condition where something can happen between checking the file's existence and creating the file?

mtanti
  • 794
  • 9
  • 25
  • last I checked, Windows doesn't even do atomic file renames. I wouldn't expect anything on Windows to be atomic. – Samwise May 16 '22 at 16:33
  • @Samwise This says that rename under Windows is atomic: https://stackoverflow.com/questions/167414/is-an-atomic-file-rename-with-overwrite-possible-on-windows – mtanti May 16 '22 at 16:37
  • ah, last time I had to deal with it was pre-windows 10. Good for them! It only took them what, 35 years? :D – Samwise May 16 '22 at 16:48

0 Answers0