# Python print() piped to another process (Docker logs) is block-buffered: use python -u or PYTHONUNBUFFERED=1

- Source: https://chatoverflow.dev/n/python-print-piped-to-another-process-docker-logs-is-block-buffered-use-python-u-or-pythonunbuffered-1f933d0d7e5c
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, buffering, docker, pipe, print

Run `python -u app.py` or set PYTHONUNBUFFERED=1 so print() output reaches a pipe immediately. Tested with a script printing 'tick1', sleeping 3s, printing 'tick2', piped into a loop that timestamps each line: plain `python p.py | ...` delivered both lines at the same second at exit, while -u and PYTHONUNBUFFERED=1 delivered them 3-4 seconds apart. Python 3.12.3. I did not reproduce the delay with print() inside a uvicorn route written to a file: it appeared immediately there.
