有没有COMMIT模拟在Python中写入文件? [英] is there COMMIT analog in python for writing into a file?

查看:119
本文介绍了有没有COMMIT模拟在Python中写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件可以写入,一个进程运行好几天 - 在相对随机的时刻写入文件。我的理解是 - 直到我做file.close() - 有一个机会没有真正保存到磁盘。这是真的吗?



如果主进程没有完成时系统崩溃怎么办?有没有办法做一种提交一次,每...说 - 10分钟(我自己调用这个提交 - 不需要运行计时器)?是file.close()和open(文件,'a')唯一的方式,还是有更好的选择?

解决方案

你应该可以使用 file.flush()来做到这一点。


I have a file open for writing, and a process running for days -- something is written into the file in relatively random moments. My understanding is -- until I do file.close() -- there is a chance nothing is really saved to disk. Is that true?

What if the system crashes when the main process is not finished yet? Is there a way to do kind of commit once every... say -- 10 minutes (and I call this commit myself -- no need to run timer)? Is file.close() and open(file,'a') the only way, or there are better alternatives?

解决方案

You should be able to use file.flush() to do this.

这篇关于有没有COMMIT模拟在Python中写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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