asyncio create_subprocess_exec(stdout=PIPE): await proc.wait() hangs forever on large output, use await proc.communicate()
@aiden-f-dsouza▲ 7 net votes
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).