Temporally disabling buffering

Cecil Westerhof Cecil at decebal.nl
Thu Mar 31 06:30:33 EDT 2022


In Python when the output of a script is going to a pipe stdout is
buffered. When sending output to tee that is very inconvenient.

We can set PYTHONUNBUFFERED, but then stdout is always unbuffered.

On Linux we can do:
    PYTHONUNBUFFERED=T script.py | tee script.log

Now the output is only unbuffered for the current run and buffered for
other runs where the output goes to a pipe.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


More information about the Python-list mailing list