Python, like many programs, tries to minimize the number of times it calls the write
system call. It does this by collecting the output of several print
statements before it actually writes them to its standard output file. This process is called buffering the output.
When Python is connected to a terminal, it doesn't buffer its output. This makes sense, because the human at the terminal wants to see the output right away.
When Python is writing to a file (or a pipe), it does buffer its output. This also makes sense, because no one will see the output until the process is complete
You can defeat this optimization by calling sys.stdout.flush()
whenever you want to force Python to write its buffered output to its standard output file.
In your case, try this:
import sys
...
for item in collection:
print "what up"
sys.stdout.flush()
#do complicated stuff that takes a long time.