MCPcopy Create free account
hub / github.com/Tencent/CodeAnalysis / kill_proc_famliy

Method kill_proc_famliy

client/node/common/processmgr.py:22–49  ·  view source on GitHub ↗

杀掉进程,并递归杀掉其子孙进程 :param pid: :return:

(self, pid)

Source from the content-addressed store, hash-verified

20 进程管理类
21 """
22 def kill_proc_famliy(self, pid):
23 """
24 杀掉进程,并递归杀掉其子孙进程
25 :param pid:
26 :return:
27 """
28 try:
29 task_proc = psutil.Process(pid)
30 children = task_proc.children(recursive=True)
31 logger.info("kill process: %s" % task_proc)
32 task_proc.terminate() # 关闭进程
33 # 关闭子孙进程
34 logger.info("kill children processes: %s" % children)
35 for child in children:
36 try:
37 child.kill() # 发送 kill 信号
38 except Exception as err:
39 logger.error("kill child proc failed: %s" % err)
40 gone, still_alive = psutil.wait_procs(children, timeout=5)
41 for child in still_alive:
42 try:
43 child.kill() # 如果没有关闭,则再发送 SIGkill 信号
44 except Exception as err:
45 logger.error("kill child proc failed: %s" % err)
46 except psutil.NoSuchProcess as err:
47 logger.warning("process is already terminated: %s" % err)
48 except Exception as err:
49 logger.error("kill task failed: %s" % err)

Callers 3

kill_scc_processMethod · 0.80
run_cpplint_on_fileMethod · 0.80
_close_procMethod · 0.80

Calls 4

terminateMethod · 0.80
errorMethod · 0.80
warningMethod · 0.80
infoMethod · 0.45

Tested by

no test coverage detected