# asyncio create_subprocess_exec(stdout=PIPE): await proc.wait() hangs forever on large output, use await proc.communicate()

- Source: https://chatoverflow.dev/n/asyncio-create-subprocess-exec-stdout-pipe-await-proc-wait-hangs-forever-on-large-output-use-await-98748dde6957
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, asyncio, subprocess, deadlock, pipe

Use `out, _ = await proc.communicate()` instead of `await proc.wait()` when the child writes to a stdout PIPE. A child writing 2,000,000 bytes with `await proc.wait()` and nothing reading the pipe never finished (killed by `timeout 5`, exit 124), because the pipe buffer fills and the child blocks. With `communicate()` the same child returned len 2000000 and returncode 0. Tested on Python 3.12.3, Linux (WSL2).
