I'm unsure about (1).
As for (2), I believe Python flushes to stdout after every new line. But, if you overload stdout to be to a file, does it flush as often?
For file operations, Python uses the operating system's default buffering unless you configure it do otherwise. You can specify a buffer size, unbuffered, or line buffered.
For example, the open function takes a buffer size argument.
"The optional buffering argument specifies the file’s desired buffer size:"
bufsize = 0 f = open('file.txt', 'w', buffering=bufsize)
You can also force flush the buffer to a file programmatically with the
with open('out.log', 'w+') as f: f.write('output is ') # some work s = 'OK.' f.write(s) f.write('\n') f.flush() # some other work f.write('done\n') f.flush()
I have found this useful when tailing an output file with