Python中的原子文件替换 [英] Atomic file replacement in Python

查看:165
本文介绍了Python中的原子文件替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python中用原子替换文件的推荐方法是什么?

What's the recommended way to replace a file atomically in Python?

如果Python脚本被中断,则存在断电等情况,文件不会以高度的不一致状态(一半写入磁盘)结束。

i.e. if the Python script is interrupted, there is a power outage etc. files do not have a high probability of ending up in an inconsistent state (half written to the disk).

Linux / UNIX平台的解决方案是首选。

A solution for Linux/UNIX platforms is preferred.

(我知道获得100%的原子操作可能取决于您的文件系统,但至少可以使腐败的机会低)

(I know getting 100% atomic operations might depend on your file system, but at least make the chances for the corruption low)

推荐答案

这篇关于Python中的原子文件替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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