Unix buffering delays output to stdout, ruins your day

Let's say you have the following program:

cat>example.py<<'EOF'
#!/usr/bin/python
import time
while True:
    print 'hello world'
    time.sleep(1)
EOF

chmod +x ./example.py

If you run this program from a terminal, it will print hello world every second.

But redirect the output to a file and something different happens:

./example.py > output &
tail -f output

You won't see any output! (At least not for a long while)

The same is true if you redirect example.py's through a unix pipe which you can do on the shell: