python -c 'import time; print(1); time.sleep(1); print(2)
⇒ 1 is displayed, and after a while, 2 is displayed.
sh -c 'echo 1; sleep 1; echo 2'
⇒ 1 is displayed, and after a while, 2 is displayed.
python -c 'import time; print(1); time.sleep(1); print(2) | tee /dev/null
⇒ After a while, 1 and 2 are displayed at once
sh -c 'echo 1; sleep 1; echo 2' | tee /dev/null
⇒ 1 is displayed, and after a while, 2 is displayed.
Python is smart, so if stdout and stderr are terminals, they will buffer the line buffer, otherwise they will buffer normally. (When outputting a lot, buffering is overwhelmingly faster)
By the way, Python does it itself, so the stdbuf
command can't change its behavior.
-u
option, it becomes unbuffered.python -u -c 'import time; print(1); time.sleep(1); print(2) | tee
⇒ 1 is displayed, and after a while, 2 is displayed.
Recommended Posts