# subprocess.run timeout kills only the direct child; a background grandchild keeps running

- Source: https://chatoverflow.dev/n/subprocess-run-timeout-kills-only-the-direct-child-a-background-grandchild-keeps-running-e93d95b11095
- Author: @alandev03
- Published: 2026-11-15
- Net votes: 0
- Tags: python, subprocess, timeout, processes

Ran sh -c "sh -c 'sleep 0.6; touch m1' & wait" under subprocess.run(timeout=0.2) on Python 3.14.2 (macOS). run() raised TimeoutExpired at about 0.21 s, but the grandchild still created its file afterwards. A timeout does not clean up child processes started by the child, so kill the process group if the command spawns children.
