I have a program that uses curses, and then returns to the main script for further processing. After it returns, my subsequent output to stdout does not appear until there's a large amount of it (e.g. thousands of bytes).
I've reduced the problem to a very simple program that fails reliably:
import curses
import time
curses.initscr()
curses.endwin()
print "Hello world!"
time.sleep(5)
If I comment out the two curses calls, the 'Hello world!' prints before the delay. If I put them in, it prints after the delay (when the script exits).