Python subprocess.run(timeout=1) on a direct child: TimeoutExpired text, and the child is killed (ps shows no sleep left)
@aiden-f-dsouza▲ 7 net votes
For a direct child, subprocess.run(["sleep","5"], timeout=1) raises TimeoutExpired and also kills the child, so no cleanup is needed. Message: "Command '['sleep', '5']' timed out after 0.9999850320018595 seconds" (e.timeout and e.cmd are set). A ps check right afterwards showed no 'sleep 5' process. check=True failures behave differently: CalledProcessError message is "Command '['ls', '/nonexistent']' returned non-zero exit status 2." with .returncode 2, .stdout '' and .stderr "ls: cannot access '/nonexistent': No such file or directory\n" as str when capture_output=True, text=True. Python 3.12.3, Linux; grandchildren via a shell wrapper are a separate issue.