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

  2. <legend id='3iLjU'><style id='3iLjU'><dir id='3iLjU'><q id='3iLjU'></q></dir></style></legend>

      <small id='3iLjU'></small><noframes id='3iLjU'>

      <tfoot id='3iLjU'></tfoot>
    1. python subprocess.Popen 挂起

      python subprocess.Popen hanging(python subprocess.Popen 挂起)

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

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

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

              1. 本文介绍了python subprocess.Popen 挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                            child = subprocess.Popen(command,
                                         shell=True,
                                         env=environment,
                                         close_fds=True,
                                         stdout=subprocess.PIPE,
                                         stderr=subprocess.STDOUT,
                                         bufsize=1,
                                                     )
                
                            subout = ""
                            with child.stdout:
                                for line in iter(child.stdout.readline, b''):
                                    subout += line
                            logging.info(subout)
                            rc = child.wait()
                

                有时(间歇性地)这会永远挂起.不确定它是否挂在 iter(child.stdout.readline)child.wait()

                some times (intermittently) this hangs forever. not sure if it hangs on iter(child.stdout.readline) or child.wait()

                i ps -ef 用于它弹出的进程并且该进程不再存在

                i ps -ef for the process it Popens and that process no longer exists

                我的猜测是它与 bufsize 有关,因此 child.stdout.readline 会永远持续,但我不知道如何测试它,因为这种情况会间歇性发生

                my guess is that it has do with bufsize so that child.stdout.readline is going on forever but i have no idea how to test it and as this happens intermittently

                我可以实现警报,但我不确定这是否合适,因为我无法真正判断 popend 进程是缓慢还是挂起

                I could implement alarm but i m not sure if that's appropriate as i cant really tell whether the popen'd process is just slow or hanging

                假设 child.stdout.readline 或 wait() 永远挂起,除了警报我还能采取什么行动?

                let's assume that either child.stdout.readline or wait() hangs forever, what actions could i take besides alarm ?

                推荐答案

                你很可能遇到了 文档中有解释:

                Popen.wait():

                等待子进程终止.设置并返回 returncode 属性.

                Wait for child process to terminate. Set and return returncode attribute.

                警告:这将在使用 stdout=PIPE 和/或 stderr=PIPE 时出现死锁,并且子进程会向管道生成足够的输出这样它会阻止等待操作系统管道缓冲区接受更多数据.使用 communicate() 来避免这种情况.

                Warning: This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that.

                解决方案是使用 Popen.communicate().

                The solution is to use Popen.communicate().

                这篇关于python subprocess.Popen 挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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='IP4Ts'><tr id='IP4Ts'><dt id='IP4Ts'><q id='IP4Ts'><span id='IP4Ts'><b id='IP4Ts'><form id='IP4Ts'><ins id='IP4Ts'></ins><ul id='IP4Ts'></ul><sub id='IP4Ts'></sub></form><legend id='IP4Ts'></legend><bdo id='IP4Ts'><pre id='IP4Ts'><center id='IP4Ts'></center></pre></bdo></b><th id='IP4Ts'></th></span></q></dt></tr></i><div id='IP4Ts'><tfoot id='IP4Ts'></tfoot><dl id='IP4Ts'><fieldset id='IP4Ts'></fieldset></dl></div>

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

                    <legend id='IP4Ts'><style id='IP4Ts'><dir id='IP4Ts'><q id='IP4Ts'></q></dir></style></legend>
                      <tbody id='IP4Ts'></tbody>
                    <tfoot id='IP4Ts'></tfoot>
                    • <bdo id='IP4Ts'></bdo><ul id='IP4Ts'></ul>