• <small id='ll1QK'></small><noframes id='ll1QK'>

    <tfoot id='ll1QK'></tfoot>

    1. <legend id='ll1QK'><style id='ll1QK'><dir id='ll1QK'><q id='ll1QK'></q></dir></style></legend>

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

      1. 等待进程直到所有子进程完成?

        wait process until all subprocess finish?(等待进程直到所有子进程完成?)
          <bdo id='jjABi'></bdo><ul id='jjABi'></ul>

              <tbody id='jjABi'></tbody>
              <tfoot id='jjABi'></tfoot>

            • <small id='jjABi'></small><noframes id='jjABi'>

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

                <legend id='jjABi'><style id='jjABi'><dir id='jjABi'><q id='jjABi'></q></dir></style></legend>
                1. 本文介绍了等待进程直到所有子进程完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个创建两个或多个子进程的主进程,我希望主进程等到所有子进程完成操作并退出?

                  I have a main process which creates two or more sub processes, I want main process to wait until all sub processes finish their operations and exits?

                   # main_script.py
                  
                   p1 = subprocess.Popen(['python script1.py']) 
                   p2 = subprocess.Popen(['python script2.py'])
                   ... 
                   #wait main process until both p1, p2 finish
                   ...
                  

                  推荐答案

                  一个 Popen 对象有一个 .wait() 方法正是为此定义的:等待给定子进程的完成(此外,对于重新调整其退出状态).

                  A Popen object has a .wait() method exactly defined for this: to wait for the completion of a given subprocess (and, besides, for retuning its exit status).

                  如果你使用这种方法,你可以防止进程僵尸停留太久.

                  If you use this method, you'll prevent that the process zombies are lying around for too long.

                  (或者,您可以使用 subprocess.call()subprocess.check_call() 用于调用和等待.如果您不需要进程的 IO,那可能就足够了.但这可能不是一个选项,因为您的 if 两个子进程似乎应该在其中运行并行,他们不会使用 (check_)call().)

                  (Alternatively, you can use subprocess.call() or subprocess.check_call() for calling and waiting. If you don't need IO with the process, that might be enough. But probably this is not an option, because your if the two subprocesses seem to be supposed to run in parallel, which they won't with (check_)call().)

                  如果你有几个子流程要等待,你可以这样做

                  If you have several subprocesses to wait for, you can do

                  exit_codes = [p.wait() for p in p1, p2]
                  

                  所有子进程完成后立即返回.然后,您将获得一个返回代码列表,您可以对其进行评估.

                  which returns as soon as all subprocesses have finished. You then have a list of return codes which you maybe can evaluate.

                  这篇关于等待进程直到所有子进程完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 画布滚动条?)
                  <legend id='F28Lb'><style id='F28Lb'><dir id='F28Lb'><q id='F28Lb'></q></dir></style></legend>

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

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

                      <tbody id='F28Lb'></tbody>
                    <tfoot id='F28Lb'></tfoot>
                          • <bdo id='F28Lb'></bdo><ul id='F28Lb'></ul>