def _terminate(self):
if self.process is None:
return
try:
parent = psutil.Process(pid=self.process.pid)
procs = parent.children(recursive=True)
procs.append(parent)
for proc in procs:
proc.terminate()
gone, still_alive = psutil.wait_procs(
procs,
timeout=constants.POPEN_TERM_TIMEOUT)
for proc in still_alive:
proc.kill()
except OSError as exc:
if exc.errno != errno.ESRCH:
# ESRCH -> process doesn't exist (already ended)
raise exc
except psutil.NoSuchProcess:
pass # probably ended already
评论列表
文章目录