What happens if I do not close the txt file

I am going to write a program for a racing car that creates txt and constantly adds new lines to it. Unfortunately, I can’t close the file, because when the car turns off, the raspberry (the program works) also closes. Therefore, I have no chance to close txt.

This is problem?

+6
source share
1 answer

Yes and no. Data is buffered in various places during the write process: the python file object, the underlying C functions, the operating system, and the disk controller. Even closing the file does not guarantee that all of these buffers are written physically. Only the first two levels are forced to write their buffers to the next level. You can do the same by clearing the file descriptor without closing it. While the power can be turned off at any time, you have to deal with the fact that some data is lost or partially written. Closing a file is important to provide free, limited operating system resources, but this does not apply to your setup.

+4
source

Source: https://habr.com/ru/post/969439/


All Articles