I came across a new-to-me Python thing today that was astonishingly useful, so thought I’d document it.
If you need to simply and globally turn off buffering for a Python script there are two options.
First, you can add the -u command line option. This is not always an option, especially if you are running Python in a script using
Second, and far more useful for me, is you can set the PYTHONUNBUFFERED environment variable to any non-zero value and it has the same effect.
Reference here for this and many other useful environment variables for Python 2.x, and you can probably guess the Python 3.x URL.