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

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

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

        等待具有多个并行作业的子进程结束

        Wait the end of subprocesses with multiple parallel jobs(等待具有多个并行作业的子进程结束)

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

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

          • <bdo id='PvYZx'></bdo><ul id='PvYZx'></ul>
              <tbody id='PvYZx'></tbody>

            • <legend id='PvYZx'><style id='PvYZx'><dir id='PvYZx'><q id='PvYZx'></q></dir></style></legend>

                <tfoot id='PvYZx'></tfoot>
                  本文介绍了等待具有多个并行作业的子进程结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在从 python 并行运行一些子进程.我想等到每个子流程都完成.我正在做一个非优雅的解决方案:

                  I'm running some subprocesses from python in parallel. I want to wait until every subprocess have finished. I'm doing a non elegant solution:

                  runcodes = ["script1.C", "script2.C"]
                  ps = []
                  for script in runcodes:
                    args = ["root", "-l", "-q", script]
                    p = subprocess.Popen(args)
                    ps.append(p)
                  while True:
                    ps_status = [p.poll() for p in ps]
                    if all([x is not None for x in ps_status]):
                      break
                  

                  有没有可以处理多个子进程的类?问题是 wait 方法阻塞了我的程序.

                  is there a class that can handle multiple subprocess? The problem is that the wait method block my program.

                  更新:我想显示计算过程中的进度:类似于4/7 subprocess finished..."

                  update: I want to show the progress during the computation: something like "4/7 subprocess finished..."

                  如果你好奇 root 编译 c++ 脚本并执行它.

                  If you are curious root compile the c++ script and execute it.

                  推荐答案

                  如果您的平台不是 Windows,您可能会选择子进程的 stdout 管道.然后,您的应用将被阻止,直到:

                  If your platform is not Windows, you could probably select against the stdout pipes of your subprocesses. Your app will then block until either:

                  • 其中一个已注册的文件描述符有一个 I/O 事件(在这种情况下,我们感兴趣的是子进程的 stdout 管道上的挂断)
                  • 投票超时

                  在 Linux 2.6.xx 中使用 epoll 的非充实示例:

                  Non-fleshed-out example using epoll with Linux 2.6.xx:

                  import subprocess
                  import select
                  
                  poller = select.epoll()
                  subprocs = {} #map stdout pipe's file descriptor to the Popen object
                  
                  #spawn some processes
                  for i in xrange(5):
                      subproc = subprocess.Popen(["mylongrunningproc"], stdout=subprocess.PIPE)
                      subprocs[subproc.stdout.fileno()] = subproc
                      poller.register(subproc.stdout, select.EPOLLHUP)
                  
                  #loop that polls until completion
                  while True:
                      for fd, flags in poller.poll(timeout=1): #never more than a second without a UI update
                          done_proc = subprocs[fd]
                          poller.unregister(fd)
                          print "this proc is done! blah blah blah"
                          ...  #do whatever
                      #print a reassuring spinning progress widget
                      ...
                      #don't forget to break when all are done
                  

                  这篇关于等待具有多个并行作业的子进程结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 画布滚动条?)
                      • <i id='8ZhcN'><tr id='8ZhcN'><dt id='8ZhcN'><q id='8ZhcN'><span id='8ZhcN'><b id='8ZhcN'><form id='8ZhcN'><ins id='8ZhcN'></ins><ul id='8ZhcN'></ul><sub id='8ZhcN'></sub></form><legend id='8ZhcN'></legend><bdo id='8ZhcN'><pre id='8ZhcN'><center id='8ZhcN'></center></pre></bdo></b><th id='8ZhcN'></th></span></q></dt></tr></i><div id='8ZhcN'><tfoot id='8ZhcN'></tfoot><dl id='8ZhcN'><fieldset id='8ZhcN'></fieldset></dl></div>
                        • <bdo id='8ZhcN'></bdo><ul id='8ZhcN'></ul>
                            <tbody id='8ZhcN'></tbody>

                          <legend id='8ZhcN'><style id='8ZhcN'><dir id='8ZhcN'><q id='8ZhcN'></q></dir></style></legend>

                            <tfoot id='8ZhcN'></tfoot>

                            <small id='8ZhcN'></small><noframes id='8ZhcN'>