Interview Prep/Python for DevOps/OS, filesystem, subprocess & CLIs

What is the pipe-buffer deadlock with `Popen`?

AdvancedConceptOS, filesystem, subprocess & CLIs
Answer

OS pipes have a limited buffer (64 KiB on Linux). If you create both stdout=PIPE and stderr=PIPE and then call p.wait() or read only one pipe, the child blocks writing to the full pipe while you block waiting for it: neither progresses. Fixes: use p.communicate() (reads both concurrently), subprocess.run(capture_output=True) which uses communicate, merge stderr into stdout, or read pipes from separate threads. The subprocess docs warn about this explicitly for wait().

All Python for DevOps questions Roadmap: Python for automation

More on OS, filesystem, subprocess & CLIs