当前位置: 首页>>代码示例>>Python>>正文


Python psutil.wait_procs方法代码示例

本文整理汇总了Python中psutil.wait_procs方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.wait_procs方法的具体用法?Python psutil.wait_procs怎么用?Python psutil.wait_procs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在psutil的用法示例。


在下文中一共展示了psutil.wait_procs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: kill_process_tree

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def kill_process_tree(pid, sig=signal.SIGTERM, include_parent=True,
                      timeout=None, on_terminate=None):
    """Kill a process tree (including grandchildren) with signal
    "sig" and return a (gone, still_alive) tuple.
    "on_terminate", if specified, is a callabck function which is
    called as soon as a child terminates.
    """

    if pid == os.getpid():
        raise RuntimeError("I refuse to kill myself")

    parent = psutil.Process(pid)
    children = parent.children(recursive=True)
    if include_parent:
        children.append(parent)

    for p in children:
        p.send_signal(sig)

    gone, alive = psutil.wait_procs(children, timeout=timeout,
                                    callback=on_terminate)
    return (gone, alive) 
开发者ID:IntegralDefense,项目名称:ACE,代码行数:24,代码来源:__init__.py

示例2: killProcTree

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def killProcTree(pid=None, including_parent=True):
    if not pid:
        # kill the process itself
        pid = os.getpid()
    parent = psutil.Process(pid)
    children = parent.children(recursive=True)
    for child in children:
        child.kill()
    psutil.wait_procs(children, timeout=5)
    if including_parent:
        parent.kill()
        parent.wait(5)


##############################################################################
# Run hashdeep on input file or directory, and output filename to digest mapping
############################################################################## 
开发者ID:osssanitizer,项目名称:osspolice,代码行数:19,代码来源:job_util.py

示例3: killProcTree

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def killProcTree(pid=None, including_parent=True):
    if not pid:
        # kill the process itself
        pid = os.getpid()
    parent = psutil.Process(pid)
    children = parent.children(recursive=True)
    for child in children:
        child.kill()
    psutil.wait_procs(children, timeout=5)
    if including_parent:
        parent.kill()
        parent.wait(5)


###########################################################
# ProgressBar
########################################################### 
开发者ID:osssanitizer,项目名称:osspolice,代码行数:19,代码来源:job_util.py

示例4: reap

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def reap(process, timeout=3):
    "Tries hard to terminate and ultimately kill all the children of this process."
    def on_terminate(proc):
        pass
        # print("process {} terminated with exit code {}".format(proc.pid, proc.returncode))

    try:
        procs = process.children(recursive=True)
        # send SIGTERM
        for p in procs:
            p.terminate()
        gone, alive = psutil.wait_procs(procs, timeout=timeout, callback=on_terminate)
        if alive:
            # send SIGKILL
            for p in alive:
                p.kill()
            gone, alive = psutil.wait_procs(alive, timeout=timeout, callback=on_terminate)
            if alive:
                # give up
                for p in alive:
                    print("process {} survived SIGKILL; giving up" % p.pid)

        process.kill()
    except:
        print("Killing failed; assuming process exited early.") 
开发者ID:battlecode,项目名称:bc18-scaffold,代码行数:27,代码来源:player_plain.py

示例5: reap_children

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def reap_children(timeout=3):
    "Tries hard to terminate and ultimately kill all the children of this process."
    def on_terminate(proc):
        pass
        # print("process {} terminated with exit code {}".format(proc, proc.returncode))

    procs = psutil.Process().children(recursive=True)
    # send SIGTERM
    for p in procs:
        p.terminate()
    gone, alive = psutil.wait_procs(procs, timeout=timeout, callback=on_terminate)
    if alive:
        # send SIGKILL
        for p in alive:
            # print("process {} survived SIGTERM; trying SIGKILL" % p.pid)
            p.kill()
        gone, alive = psutil.wait_procs(alive, timeout=timeout, callback=on_terminate)
        if alive:
            # give up
            for p in alive:
                print("process {} survived SIGKILL; giving up" % p.pid) 
开发者ID:battlecode,项目名称:bc18-scaffold,代码行数:23,代码来源:gui.py

示例6: kill_proc

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def kill_proc(proc):
    """
    Kill a process and its children processes
    :param proc: Process class defined in psutil
    :return: None
    """
    try:
        children = proc.children()
        for child in children:
            try:
                child.terminate()
            except:
                pass
        gone, still_alive = psutil.wait_procs(children, timeout=3)
        for p in still_alive:
            p.kill()
        proc.kill()
    except:
        pass 
开发者ID:liyao001,项目名称:BioQueue,代码行数:21,代码来源:bioqueue.py

示例7: test_recursive_terminate

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def test_recursive_terminate(use_psutil):
    event = ctx_loky.Event()
    p = ctx_loky.Process(target=_run_nested_delayed, args=(4, 1000, event))
    p.start()

    # Wait for all the processes to be launched
    if not event.wait(30):
        recursive_terminate(p, use_psutil=use_psutil)
        raise RuntimeError("test_recursive_terminate was not able to launch "
                           "all nested processes.")

    children = psutil.Process(pid=p.pid).children(recursive=True)
    recursive_terminate(p, use_psutil=use_psutil)

    # The process can take some time finishing so we should wait up to 5s
    gone, alive = psutil.wait_procs(children, timeout=5)
    msg = "Should be no descendant left but found:\n{}"
    assert len(alive) == 0, msg.format(alive) 
开发者ID:joblib,项目名称:loky,代码行数:20,代码来源:test_loky_backend.py

示例8: kill_proc_tree

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def kill_proc_tree(pid, sig=signal.SIGTERM, include_parent=True,
                   timeout=None, on_terminate=None):
    """Kill a process tree (including grandchildren) with signal
    "sig" and return a (gone, still_alive) tuple.
    "on_terminate", if specified, is a callabck function which is
    called as soon as a child terminates.
    """
    if pid == os.getpid():
        raise RuntimeError("I refuse to kill myself")
    parent = psutil.Process(pid)
    children = parent.children(recursive=True)
    if include_parent:
        children.append(parent)
    for p in children:
        p.send_signal(sig)
    gone, alive = psutil.wait_procs(children, timeout=timeout,
                                    callback=on_terminate)
    return (gone, alive) 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:20,代码来源:Web_psutil_Kill_Processes.py

示例9: die_die_die

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def die_die_die(self: "Helpers", parent: ProcessType) -> None:
        if isinstance(parent, int):
            try:
                par = Process(parent)
            except NoSuchProcess:
                self.warn("Unable to kill process id:{}".format(parent))
                return
        else:
            par = parent
        for child_process in par.children():
            self.die_die_die(child_process)
            if child_process.is_running():
                child_process.terminate()
                _, alive = wait_procs([child_process], timeout=3)
                for p in alive:
                    p.kill() 
开发者ID:rasjani,项目名称:robotframework-seleniumtestability,代码行数:18,代码来源:__init__.py

示例10: kill_all_subprocesses

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def kill_all_subprocesses(pid=None, include_self=False):
    # kill all subprocesses that could have been spawn from the current process
    try:
        proc = psutil.Process(pid)
    except Exception:
        # if no such process
        return
    procs = proc.children(recursive=True) + ([proc] if include_self else [])
    if not procs:
        return
    for p in procs:
        p.terminate()
    alive = psutil.wait_procs(procs, timeout=3)[-1]
    if alive:
        for p in alive:
            p.kill()
    alive = psutil.wait_procs(procs, timeout=3)[-1]
    if alive:
        for p in alive:
            env.logger.warning(f'Failed to kill subprocess {p.pid}') 
开发者ID:vatlab,项目名称:sos,代码行数:22,代码来源:executor_utils.py

示例11: close

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def close(self):
        """Close SSH tunnel."""
        logging.debug('Closing tunnel "%s"', self.context.uri)

        if self._closed:
            return

        # Find all ssh instances for user with uri tunnel the hard way...
        targets = [
            p
            for p in psutil.process_iter(attrs=['name', 'username', 'cmdline'])
            if p.info['username'] == getpass.getuser()
            and p.info['name'] == 'ssh'
            and self.context.local_socket in ' '.join(p.info['cmdline'])
        ]  # yapf: disable

        # ask nicely for ssh to quit, reap results
        for proc in targets:
            proc.terminate()
        _, alive = psutil.wait_procs(targets, timeout=300)

        # kill off the uncooperative, then report any stragglers
        for proc in alive:
            proc.kill()
        _, alive = psutil.wait_procs(targets, timeout=300)

        for proc in alive:
            logging.info('process %d survived SIGKILL, giving up.', proc.pid)

        with suppress(OSError):
            os.remove(self.context.local_socket)
        self._closed = True 
开发者ID:containers,项目名称:python-podman,代码行数:34,代码来源:tunnel.py

示例12: wait_procs

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def wait_procs(*args, **kwargs):
    return psutil.wait_procs(*args, **kwargs) 
开发者ID:masmu,项目名称:pulseaudio-dlna,代码行数:4,代码来源:psutil.py

示例13: test_wait_procs_no_timeout

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def test_wait_procs_no_timeout(self):
        sproc1 = get_test_subprocess()
        sproc2 = get_test_subprocess()
        sproc3 = get_test_subprocess()
        procs = [psutil.Process(x.pid) for x in (sproc1, sproc2, sproc3)]
        for p in procs:
            p.terminate()
        gone, alive = psutil.wait_procs(procs) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:10,代码来源:test_system.py

示例14: killProcTree

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def killProcTree(pid=None, including_parent=True):
    if not pid:
        # kill the process itself
        pid = os.getpid()
    parent = psutil.Process(pid)
    children = parent.children(recursive=True)
    for child in children:
        child.kill()
    psutil.wait_procs(children, timeout=5)
    if including_parent:
        parent.kill()
        parent.wait(5) 
开发者ID:osssanitizer,项目名称:osspolice,代码行数:14,代码来源:job_util.py

示例15: reap_children

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import wait_procs [as 别名]
def reap_children(recursive=False):
    """Terminate and wait() any subprocess started by this test suite
    and any children currently running, ensuring that no processes stick
    around to hog resources.
    If resursive is True it also tries to terminate and wait()
    all grandchildren started by this process.
    """
    # Get the children here before terminating them, as in case of
    # recursive=True we don't want to lose the intermediate reference
    # pointing to the grandchildren.
    children = psutil.Process().children(recursive=recursive)

    # Terminate subprocess.Popen.
    while _subprocesses_started:
        subp = _subprocesses_started.pop()
        terminate(subp)

    # Collect started pids.
    while _pids_started:
        pid = _pids_started.pop()
        terminate(pid)

    # Terminate children.
    if children:
        for p in children:
            terminate(p, wait_timeout=None)
        gone, alive = psutil.wait_procs(children, timeout=GLOBAL_TIMEOUT)
        for p in alive:
            warn("couldn't terminate process %r; attempting kill()" % p)
            terminate(p, sig=signal.SIGKILL)


# ===================================================================
# --- OS
# =================================================================== 
开发者ID:giampaolo,项目名称:psutil,代码行数:37,代码来源:__init__.py


注:本文中的psutil.wait_procs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。