Data persistence error after sudden power cut

EDIT: Something I haven’t mentioned is that before cutting the power I print the file through ssh with cat and it’s definitely not empty and size increases as expected.


Thanks for the answer @thgreasi. I’m going to respond under your lines:

Only the current file being edited is empty. The rest of the files are okay.

I’ve tried adding f.flush() and it didn’t help. I’ll try os.fsync() today and let you know.

No, not really, but I’ve tried to write every 5 seconds instead of every 1 second and the problem remains. I guess if it were a timing problem, 5 seconds to write and flush the contents should be more than enough.

I’m aware of this, I just wanted to run a quick demo. I’ve also tried to open the file for appending data but the behavior is similar. In this case, the file is not completely empty but it’s still missing some lines.

Indeed. I am just trying to understand first if I’m missing something.

Thanks again!