I'm stuggeling with an issue with python. I used Python 2.7.13 and Python 3.6.0 on Red Hat Enterprise Linux Server release 7.1 (Maipo). In order to monitor the proccesses output, I want to use tail -f
to take a live look into the STDOUT and STDERR. The Keyword here is unbuffered output. Many suggestion on the internet say use python -u ...
or the environment variable PYTHONUNBUFFERED like PYTHONUNBUFFERED=1 python ...
or stdbuf -e0 -o0 python ...
. Nevertheless nothing is wokring for the following test script.
import sys
import time
while(True):
print("Test String")
time.sleep(1);
For all different commands I always have buffered output. Even though when I want to use STDERR. It's still buffered which really confuses me because STDERR should be unbuffered by default. Using sys.stdout.flush()
or sys.stderr.flush()
is also not doing the job. When using flush=True
inside print()
it's working as intended.
I'm looking for a solution which doesn't make it necessary to edit code because I can't edit all programs in order to get unbuffered and immediately flushed out output. How can I achieve this?
Looking forward to your answers!
Best wishes!
print(flush=True)
function. – Muskmelonpython -u
orPYTHONUNBUFFERED
instead that they're working.. I don't even know why they're not working as advertised. – Carpophagousprint("Test String")
to do that it doesn't? no matter if buffered or not, the output will be the same. – Floruitprint
withtail
to see how the progress is.print("Test String")
is just a dummy script with which I want to test that. Until now, stdout and stderr as well asprint
create buffered output when redirecting them into a file. Therefore it is hard to monitor my logs withtailf
because I get new output every 4-6 hours. – Carpophagous