def _abort(self):
"""Terminate all live jobs."""
for i, pid in enumerate(self._slots):
if pid != 0:
if not is_windows:
try:
os.killpg(pid, signal.SIGTERM)
except OSError:
# If the process with pid did not have time to become a process group leader,
# then pgid does not exist and os.killpg could not kill the process,
# so re-try kill the process only.
try:
os.kill(pid, signal.SIGTERM)
except OSError:
pass
else:
root_proc = psutil.Process(pid)
children = root_proc.children(recursive=True) + [root_proc]
for proc in children:
try:
# Would be easier to use proc.terminate() here but psutils
# (up to version 5.4.0) on Windows terminates processes with
# the 0 signal/code, making the outcome of the terminated
# process indistinguishable from a successful execution.
os.kill(proc.pid, signal.SIGTERM)
except OSError:
pass
psutil.wait_procs(children, timeout=1)
self._slots[i] = 0
评论列表
文章目录