Use sys.stdout.write and sys.stdout.flush() to avoid possible output buffering.