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?