强制结束subprocess.Popen开启的任务
需要使用到psutil库,可以通过pip安装
import subprocessimport psutildef kill(proc_pid):process = psutil.Process(proc_pid)for proc in process.children(recursive=True):proc.kill()process.kill()proc = subprocess.Popen(["infinite_app", "param"], shell=True)
try:proc.wait(timeout=3)
except subprocess.TimeoutExpired:kill(proc.pid)