<legend id='lN1HE'><style id='lN1HE'><dir id='lN1HE'><q id='lN1HE'></q></dir></style></legend>

    <tfoot id='lN1HE'></tfoot>
      <i id='lN1HE'><tr id='lN1HE'><dt id='lN1HE'><q id='lN1HE'><span id='lN1HE'><b id='lN1HE'><form id='lN1HE'><ins id='lN1HE'></ins><ul id='lN1HE'></ul><sub id='lN1HE'></sub></form><legend id='lN1HE'></legend><bdo id='lN1HE'><pre id='lN1HE'><center id='lN1HE'></center></pre></bdo></b><th id='lN1HE'></th></span></q></dt></tr></i><div id='lN1HE'><tfoot id='lN1HE'></tfoot><dl id='lN1HE'><fieldset id='lN1HE'></fieldset></dl></div>
        <bdo id='lN1HE'></bdo><ul id='lN1HE'></ul>

    1. <small id='lN1HE'></small><noframes id='lN1HE'>

    2. subprocess:删除Windows中的子进程

      subprocess: deleting child processes in Windows(subprocess:删除Windows中的子进程)

          <bdo id='TYC0O'></bdo><ul id='TYC0O'></ul>

          <tfoot id='TYC0O'></tfoot>
            <legend id='TYC0O'><style id='TYC0O'><dir id='TYC0O'><q id='TYC0O'></q></dir></style></legend>

            <i id='TYC0O'><tr id='TYC0O'><dt id='TYC0O'><q id='TYC0O'><span id='TYC0O'><b id='TYC0O'><form id='TYC0O'><ins id='TYC0O'></ins><ul id='TYC0O'></ul><sub id='TYC0O'></sub></form><legend id='TYC0O'></legend><bdo id='TYC0O'><pre id='TYC0O'><center id='TYC0O'></center></pre></bdo></b><th id='TYC0O'></th></span></q></dt></tr></i><div id='TYC0O'><tfoot id='TYC0O'></tfoot><dl id='TYC0O'><fieldset id='TYC0O'></fieldset></dl></div>
            • <small id='TYC0O'></small><noframes id='TYC0O'>

                  <tbody id='TYC0O'></tbody>
                本文介绍了subprocess:删除Windows中的子进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在 Windows 上,subprocess.Popen.terminate 调用 win32 的 TerminalProcess.但是,我看到的行为是我试图终止的进程的子进程仍在运行.这是为什么?如何确保进程启动的所有子进程都被杀死?

                On Windows, subprocess.Popen.terminate calls win32's TerminalProcess. However, the behavior I see is that child processes of the process I am trying to terminate are still running. Why is that? How do I ensure all child processes started by the process are killed?

                推荐答案

                通过使用psutil:

                import psutil, os
                
                def kill_proc_tree(pid, including_parent=True):    
                    parent = psutil.Process(pid)
                    children = parent.children(recursive=True)
                    for child in children:
                        child.kill()
                    gone, still_alive = psutil.wait_procs(children, timeout=5)
                    if including_parent:
                        parent.kill()
                        parent.wait(5)
                
                me = os.getpid()
                kill_proc_tree(me)
                

                这篇关于subprocess:删除Windows中的子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)
                <tfoot id='he8pb'></tfoot>

                <small id='he8pb'></small><noframes id='he8pb'>

                  • <bdo id='he8pb'></bdo><ul id='he8pb'></ul>

                    <i id='he8pb'><tr id='he8pb'><dt id='he8pb'><q id='he8pb'><span id='he8pb'><b id='he8pb'><form id='he8pb'><ins id='he8pb'></ins><ul id='he8pb'></ul><sub id='he8pb'></sub></form><legend id='he8pb'></legend><bdo id='he8pb'><pre id='he8pb'><center id='he8pb'></center></pre></bdo></b><th id='he8pb'></th></span></q></dt></tr></i><div id='he8pb'><tfoot id='he8pb'></tfoot><dl id='he8pb'><fieldset id='he8pb'></fieldset></dl></div>
                    <legend id='he8pb'><style id='he8pb'><dir id='he8pb'><q id='he8pb'></q></dir></style></legend>
                      <tbody id='he8pb'></tbody>