Run in unbuffered mode, so that output is printed immediately rather than when the buffer reaches a certain size.

There are multiple ways to achieve this.

StackOverflow discussion.

$ python -u

Or if you are not using /usr/bin/env python you can add the flag to your script.

#!/usr/bin/python -u

Set PYTHONUNBUFFERED in the shell or within your script on os module.

Or within a script on print.

print('Hello, World!', flush=True)

Or with a partial:

import functools

print = functools.partial(print, flush=True)

print('Hello, World!')