Is output buffering enabled by default in Python's interpreter for sys.stdout
?
If the answer is positive, what are all the ways to disable it?
Suggestions so far:
- Use the
-u
command line switch - Wrap
sys.stdout
in an object that flushes after every write - Set
PYTHONUNBUFFERED
env var sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
Is there any other way to set some global flag in sys
/sys.stdout
programmatically during execution?
If you just want to flush after a specific write using print
, see How can I flush the output of the print function?.
-u
is that it won't work for compiled bytecode or for apps with a__main__.py
file as entry point. – Deluge