Skip to content
Latchkey

python -u: Unbuffered Output for CI Logs

Stop Python buffering its logs so CI shows output live.

python -u forces stdout and stderr to be unbuffered. In CI, this makes log lines appear immediately instead of arriving in a burst at the end (or being lost on a crash).

What it does

Disables buffering on the standard streams so writes flush right away. Without it, output to a non-TTY (a CI log) is block-buffered and can appear delayed or out of order.

Common usage

Terminal
python -u script.py
# Equivalent via environment variable:
PYTHONUNBUFFERED=1 python script.py

Common CI symptom: missing logs on crash

When a job is killed (timeout, OOM) before buffered output flushes, the last log lines never appear, hiding the real cause. Run with -u or set PYTHONUNBUFFERED=1 so logs are not lost.

Terminal
# Make CI logs reliable:
export PYTHONUNBUFFERED=1
python long_running.py

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →