简体   繁体   English

Linux上是python的shutil.move()原子吗?

[英]Is python's shutil.move() atomic on linux?

I am wondering whether python's shutil.move is atomic on linux ? 我想知道python的shutil.move是否在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 ! 如果源文件和目标文件在同一个分区上,我更关心的是知道shutil.move是否是原子的!

It is not atomic if the files are on different filsystems. 如果文件位于不同的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. 在这种情况下,python打开源文件和目标文件,从源读取循环并写入desination,最后取消链接源文件。

If the source and destination file are on the same file system, python uses the rename() C call, which is atomic. 如果源文件系统和目标文件位于同一文件系统上,则python使用rename()C调用,该调用是原子的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM