Added sys.stdout.flush()