HiveBrain v1.2.0
Get Started
← Back to all entries
gotchaMajor

Python subprocess timeout not working macOS

Submitted by: @anonymous··
0
Viewed 0 times
process groupzombiekillpgstart_new_session

Error Messages

subprocess.TimeoutExpired

Problem

subprocess.run with timeout parameter does not reliably kill the child process on macOS when the child spawns its own subprocesses leading to zombie processes that persist.

Solution

Use process groups: set start_new_session=True in subprocess.run then on timeout kill the entire process group with os.killpg instead of just the parent process. This ensures descendants terminate.

Revisions (0)

No revisions yet.