Why Your Python Subprocess Hangs (And How to Fix the Deadlock)

You wrote what looks like perfectly reasonable Python code: 1 2 3 4 5 6 7 8 9 10 11 12 import subprocess proc = subprocess.Popen( ["some-command"], stdout=subprocess.PIPE, stderr=subprocess.PIPE ) # Read the output output = proc.stdout.read() errors = proc.stderr.read() proc.wait() And it hangs. Forever. No error, no timeout, just… nothing. Welcome to the pipe buffer deadlock, one of Python’s most frustrating subprocess gotchas. Why This Happens The problem is OS pipe buffers. When you create a subprocess with stdout=subprocess.PIPE, the OS creates a pipe with a fixed buffer size (typically 64KB on Linux). ...

March 16, 2026 · 4 min · 741 words · Rob Washington