How come a file doesn't get written until I stop the program?

前端 未结 7 2112
旧时难觅i
旧时难觅i 2020-11-29 03:31

I\'m running a test, and found that the file doesn\'t actually get written until I control-C to abort the program. Can anyone explain why that would happen?

I expec

7条回答
  •  -上瘾入骨i
    2020-11-29 04:10

    You have to force the write, so I i use the following lines to make sure a file is written:

    # Two commands together force the OS to store the file buffer to disc
        f.flush()
        os.fsync(f.fileno())
    

提交回复
热议问题