Python3: Buffering causes confusion

I’m wondering if it is worth changing python3 to run without output buffering?

There are a lot of people who get stuck thinking input is broken due to the last line appearing not to be read (as printing it gets buffered until the next print() to stdout / input() statement) so any infinite loop will tend to leave some messages unprinted.

It’ll cause a small performance decrease for output / debug messages, but unless someone is printing a huge amount it shouldn’t be that noticeable.

Output buffering can be disabled by running python with the -u argument or by setting the environment variable PYTHONUNBUFFERED=1 before running the script.

Alternatively the stub generator could be updated with flush=True on the example stderr prints which would show people that it’s expected but still allow people who print a lot to remove it for performance.

5 Likes

Yeah, it’s true it’s annoying. I’ll submit this idea to the devs.

We updated the stub with “flush = true” for the stderr. Hopefully, it will help Python players to understand their timeout issues.

1 Like