Added sys.stdout.flush() commands to flush python output.