parallel_loop.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:picire 作者: renatahodovan 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号