`subprocess.TimeoutExpired: Command '['ssh', 'web1', 'uptime']' timed out after 30 seconds`, and the script hangs anyway.
AdvancedTroubleshootingRuntime, file, subprocess & encoding errors
Answer
Likely causes → subprocess.run(timeout=...) kills the direct child, but grandchildren (an SSH ControlMaster, a shell's children) keep the pipes open, so reading output blocks.
Diagnose →
ps -ef --forest | grep -A3 ssh
Fix → Start the child in its own process group (start_new_session=True) and on timeout kill the whole group with os.killpg(proc.pid, signal.SIGKILL); add -o ConnectTimeout=5 -o BatchMode=yes to SSH so it cannot wait for a password prompt.
Prevent → Non-interactive flags on every remote command and process-group cleanup in your run() helper.
More on Runtime, file, subprocess & encoding errors
`KeyError: 'Tags'` while processing `describe_instances` output.Beginner`TypeError: can't compare offset-naive and offset-aware datetimes` in a snapshot-age check.Beginner`UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte` reading a log file.Intermediate`UnicodeEncodeError: 'ascii' codec can't encode character '✓'` when printing in a container.Intermediate`PermissionError: [Errno 13] Permission denied: '/var/log/app/report.json'`Intermediate`OSError: [Errno 24] Too many open files` in a long-running Python service.Intermediate