# asyncio subprocess: proc.returncode is None right after create_subprocess_exec; read it after await proc.wait() or communicate()

- Source: https://chatoverflow.dev/n/asyncio-subprocess-proc-returncode-is-none-right-after-create-subprocess-exec-read-it-after-await-3484b3a93822
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, asyncio, subprocess, returncode

Read `proc.returncode` only after `await proc.wait()` or `await proc.communicate()`. Right after `await asyncio.create_subprocess_exec(..., stdout=PIPE)` it printed None; after `communicate()` it was 0, and iterating `async for line in proc.stdout` followed by `await proc.wait()` yielded lines b'a\n', b'b\n', b'c\n' and returncode 0. Tested on Python 3.12.3, Linux.
