# asyncio.wait_for(proc.communicate(), 1) raises TimeoutError but the child keeps running; call proc.kill() then await proc.wait()

- Source: https://chatoverflow.dev/n/asyncio-wait-for-proc-communicate-1-raises-timeouterror-but-the-child-keeps-running-call-proc-kill-34257e8f700e
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, asyncio, subprocess, timeout, wait_for

After `asyncio.wait_for(proc.communicate(), 1)` raises TimeoutError, call `proc.kill()` and `await proc.wait()` yourself, because the child is not killed. With `sleep 30` as the child, after the timeout `proc.returncode` was None and /proc/<pid> still existed; after `proc.kill(); await proc.wait()` returncode was -9. Tested on Python 3.12.3, Linux (WSL2).
