Use sys.stdout.flush everywhere