在Linux上python的shutil.move()是原子的吗? [英] Is python's shutil.move() atomic on linux?

查看:158
本文介绍了在Linux上python的shutil.move()是原子的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道python的shutil.move是否在Linux上是原子的?如果源文件和目标文件位于两个不同的分区上,或者与它们位于同一分区上时,行为是不同的吗?

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 ?

我更担心知道,如果源文件和目标文件位于同一分区上,shutil.move是否是原子的!

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

推荐答案

如果文件位于不同的filsystem上,则不是原子的.在这种情况下,python将打开源文件和目标文件,在从源文件读取和写入目标文件时循环执行,最后取消链接源文件.

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.

如果源文件和目标文件位于同一文件系统上,则python使用named()C调用,这是原子的.

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

这篇关于在Linux上python的shutil.move()是原子的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆