This sounds like a buffered vs. non-buffered output issue. My
guess would be that if you increased 10 to something larger, the
output buffer would flush at various intervals. The solution on
the Mac (or other *nix-like OSes) would be to either start python
in unbuffered mode:
python -u mycode.py
Alternatively, you can force a flush of the output buffer at each
iteration:
import sys
for i in range(10):
print i
sys.stdout.flush()
sleep(2)
Lastly, you can force all standard-output in your program to be
unbuffered without the "-u" parameter:
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
Hope this helps,
-tkc
And if you're using -u a lot, the PYTHONUNBUFFERED environment
variable can also be set (but not empty), so that python adds the
option automatically.