Skip to content Skip to sidebar Skip to footer

What Would Happen If I Abruptly Close My Script While It's Still Doing File I/o Operations?

here's my question: I'm writing a script to check if my website running all right, the basic idea is to get the server response time and similar stuff every 5 minutes or so, and th

Solution 1:

According to the python io documentation, buffering is handled according to the buffering parameter to the open function.

The default behavior in this case would be either the device's block size or io.DEFAULT_BUFFER_SIZE if the block size can't be determined. This is probably something like 4096 bytes.

In short, that example will write nothing. If you were writing something long enough that the buffer was written once or twice, you'd have multiples of the buffer size written. And you can always manually flush the buffer with flush().

(If you specify buffering as 0 and the file mode as binary, you'd get "This i". That's the only way, though)

As @sven pointed out, python isn't doing the buffering. When the program is terminated, all open file descriptors are closed and flushed by the operating system.

Post a Comment for "What Would Happen If I Abruptly Close My Script While It's Still Doing File I/o Operations?"