I have a python script that looks something like this:
for item in collection:
print "what up"
#do complicated stuff that takes a long time.
In bash, I run this script by doing the following:
$ python my.py | tee my_file.txt
However, all I see in bash is a blank line until the program finishes. Then, all of the print statements come all at one.
Is this the expected operation of tee? Can I use tee to see the output in real-time?
import sys
" and on an indented line below the print statement do "sys.stdout.flush()
" – Restivo-u
is here to "force stdin, stdout and stderr to be totally unbuffered." and would solve your problem. – Iterative