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


Python Process.kill方法代码示例

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


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

示例1: kill_proc_tree

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import kill [as 别名]
def kill_proc_tree(pid, including_parent=True, timeout=5):
    try:
        parent = Process(pid)
    except NoSuchProcess:
        return
    children = parent.children(recursive=True)
    for child in children:
        if verbose.kill:
            print("killing {}".format(child.pid))
        try:
            child.kill()
            child.terminate()
        except NoSuchProcess:
            pass
    gone, still_alive = wait_procs(children, timeout=timeout)
    if including_parent:
        try:
            if verbose.kill:
                print("killing {}".format(parent.pid))
            parent.kill()
            parent.terminate()
            try:
                parent.wait(timeout)
            except TimeoutExpired:
                print("timeout expired, process may still be around: {}".format(parent.pid))
        except NoSuchProcess:
            pass
开发者ID:alon,项目名称:emolog,代码行数:29,代码来源:util.py

示例2: _psutil_kill_pid

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import kill [as 别名]
def _psutil_kill_pid(pid):
    """
    http://stackoverflow.com/questions/1230669/subprocess-deleting-child-processes-in-windows
    """
    try:
        parent = Process(pid)
        for child in parent.children(recursive=True):
            child.kill()
        parent.kill()
    except NoSuchProcess:
        return
开发者ID:galaxyproject,项目名称:pulsar,代码行数:13,代码来源:kill.py

示例3: wait_output

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import kill [as 别名]
def wait_output(settings, popen):
    """Returns `True` if we can get output of the command in the
    `wait_command` time.

    Command will be killed if it wasn't finished in the time.

    """
    proc = Process(popen.pid)
    try:
        proc.wait(settings.wait_command)
        return True
    except TimeoutExpired:
        for child in proc.get_children(recursive=True):
            child.kill()
        proc.kill()
        return False
开发者ID:emptyaitch,项目名称:thefuck,代码行数:18,代码来源:main.py

示例4: _wait_output

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import kill [as 别名]
    def _wait_output(popen, is_slow):
        """Returns `True` if we can get output of the command in the
        `settings.wait_command` time.

        Command will be killed if it wasn't finished in the time.

        :type popen: Popen
        :rtype: bool

        """
        proc = Process(popen.pid)
        try:
            proc.wait(settings.wait_slow_command if is_slow
                      else settings.wait_command)
            return True
        except TimeoutExpired:
            for child in proc.children(recursive=True):
                child.kill()
            proc.kill()
            return False
开发者ID:josephfrazier,项目名称:thefuck,代码行数:22,代码来源:types.py


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