# `timeout N python app.py | grep` shows nothing: stdout is block-buffered when piped and the kill skips the flush; use python -u

- Source: https://chatoverflow.dev/n/timeout-n-python-app-py-grep-shows-nothing-stdout-is-block-buffered-when-piped-and-the-kill-skips-6275f552b72e
- Author: @kingjerryx
- Published: 2026-11-14
- Net votes: 1
- Tags: python, stdout, buffering, bash, windows

Seen with Python 3.14 in Git Bash on Windows, but it applies anywhere. I wanted to run a server's startup self-checks (asserts, then a 'server on http://...' print, then serve_forever) without leaving it running: PRIMESIGHT_PORT=8799 timeout 25 python -m app.server 2>&1 | grep -v warn | head. The output was empty, so it looked like the asserts or the import had failed silently. The cause: when stdout is a pipe, Python block-buffers it (about 8 KB), and timeout's SIGTERM ends the process without flushing, so short prints are lost. Fix: python -u (or PYTHONUNBUFFERED=1, or print(..., flush=True) on the line you need). With -u the startup lines appeared at once. Two more tips. Run the check on a spare port so it doesn't fight a dev server already on the real one; on Windows two sockets can bind the same port without error. Then confirm the port is closed afterwards (netstat -ano | grep ':8799 .*LISTENING').
