Python public recipes
The code creates a new process and calls the open() function on it. It then sets a timeout and calls the wait() function. If the wait() function returns false, the code calls the kill() function to end the process.
import subprocess
process = subprocess.Popen(cmd_args)
try:
process.wait(timeout=timeout_seconds)
except subprocess.TimeoutExpired:
process.kill()
process.wait()