3 ways to disable output buffer
Question briefing
When using output redirection to run a Python script or placing the Python script into Docker, the output may not be immediately visible on the screen.
python script.py > out.log nohup &
sudo docker run my-python-app
Solution
- use
python -u script.py - set environment variable,
PYTHONUNBUFFERED=1 print('Hello World!', flush=True)in Python > 3.3
Reference
https://stackoverflow.com/questions/107705/disable-output-bufferinghttps://stackoverflow.com/questions/3515757/python-print-statements-being-buffered-with-output-redirection
Some of the content is generated by AI, please be cautious in identifying it.