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

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

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

      <tfoot id='S4qTy'></tfoot>

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

    1. 在 Python 中使用子进程从进程中无缓冲读取

      Unbuffered read from process using subprocess in Python(在 Python 中使用子进程从进程中无缓冲读取)
          <tfoot id='nvTn4'></tfoot>
          <legend id='nvTn4'><style id='nvTn4'><dir id='nvTn4'><q id='nvTn4'></q></dir></style></legend>

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

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

                  <tbody id='nvTn4'></tbody>

                本文介绍了在 Python 中使用子进程从进程中无缓冲读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试从产生长时间且耗时的输出的进程中读取.但是,我想捕捉它的输出以及何时.但是使用类似下面的东西似乎在缓冲命令的输出,所以我最终一次得到了输出行:

                I am trying to read from a process that produces long and time-consuming output. However, I want to catch it's output as and when it is produced. But using something like the following seems to be buffering the command's output, so I end up getting the output lines all at once:

                p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, bufsize=0)
                    for line in p.stdout:
                        print line
                

                我正在 MacOS 10.5 上尝试这个

                I am trying this on MacOS 10.5

                推荐答案

                文件迭代器正在做一些内部缓冲 独立.试试这个:

                The file iterator is doing some internal buffering on its own. Try this:

                line = p.stdout.readline()
                while line:
                    print line
                    line = p.stdout.readline()
                

                您还需要确保您正在运行的进程实际上经常刷新其输出缓冲区.

                You also need to make sure the process you are running is actually flushing its output buffers frequently.

                这篇关于在 Python 中使用子进程从进程中无缓冲读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                How to extend Python class init(如何扩展 Python 类初始化)
                What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                Initialize list with same bool value(使用相同的布尔值初始化列表)
                setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                  <tbody id='LaDWN'></tbody>

                  <legend id='LaDWN'><style id='LaDWN'><dir id='LaDWN'><q id='LaDWN'></q></dir></style></legend>
                  1. <small id='LaDWN'></small><noframes id='LaDWN'>

                    • <bdo id='LaDWN'></bdo><ul id='LaDWN'></ul>
                          <tfoot id='LaDWN'></tfoot>

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