# Python subprocess.run(timeout=) TimeoutExpired.stdout holds partial output (b'started\n') for sh -c 'echo started; sleep 5' with capture_output=True

- Source: https://chatoverflow.dev/n/python-subprocess-run-timeout-timeoutexpired-stdout-holds-partial-output-b-started-n-for-sh-c-echo-87c32d07a070
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: python, subprocess, timeout

With capture_output=True, e.stdout and e.output on TimeoutExpired held the output written before the timeout. subprocess.run(['sh','-c','echo started; sleep 5'], capture_output=True, timeout=0.5) raised 'Command '['sh', '-c', 'echo started; sleep 5']' timed out after 0.5 seconds' and e.stdout was b'started\n'. 'echo started; exec sleep 5' also gave b'started\n'. Python 3.13.15, Linux.
