<tfoot id='qZR3N'></tfoot>

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

      1. <legend id='qZR3N'><style id='qZR3N'><dir id='qZR3N'><q id='qZR3N'></q></dir></style></legend>
      2. <i id='qZR3N'><tr id='qZR3N'><dt id='qZR3N'><q id='qZR3N'><span id='qZR3N'><b id='qZR3N'><form id='qZR3N'><ins id='qZR3N'></ins><ul id='qZR3N'></ul><sub id='qZR3N'></sub></form><legend id='qZR3N'></legend><bdo id='qZR3N'><pre id='qZR3N'><center id='qZR3N'></center></pre></bdo></b><th id='qZR3N'></th></span></q></dt></tr></i><div id='qZR3N'><tfoot id='qZR3N'></tfoot><dl id='qZR3N'><fieldset id='qZR3N'></fieldset></dl></div>
          <bdo id='qZR3N'></bdo><ul id='qZR3N'></ul>
      3. 在不破坏管道的情况下与进程多次通信?

        时间:2023-07-22

        <small id='0mJ4J'></small><noframes id='0mJ4J'>

          <tbody id='0mJ4J'></tbody>

              1. <i id='0mJ4J'><tr id='0mJ4J'><dt id='0mJ4J'><q id='0mJ4J'><span id='0mJ4J'><b id='0mJ4J'><form id='0mJ4J'><ins id='0mJ4J'></ins><ul id='0mJ4J'></ul><sub id='0mJ4J'></sub></form><legend id='0mJ4J'></legend><bdo id='0mJ4J'><pre id='0mJ4J'><center id='0mJ4J'></center></pre></bdo></b><th id='0mJ4J'></th></span></q></dt></tr></i><div id='0mJ4J'><tfoot id='0mJ4J'></tfoot><dl id='0mJ4J'><fieldset id='0mJ4J'></fieldset></dl></div>
                <tfoot id='0mJ4J'></tfoot>
                  <bdo id='0mJ4J'></bdo><ul id='0mJ4J'></ul>
                  <legend id='0mJ4J'><style id='0mJ4J'><dir id='0mJ4J'><q id='0mJ4J'></q></dir></style></legend>
                • 本文介绍了在不破坏管道的情况下与进程多次通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这不是我第一次遇到这个问题,而且真的很困扰我.每当我使用 Python subprocess 模块打开管道时,我只能与它 communicate 一次,如文档所述:从 stdout 和 stderr 读取数据,直到结束-of-file 到达

                  It's not the first time I'm having this problem, and it's really bugging me. Whenever I open a pipe using the Python subprocess module, I can only communicate with it once, as the documentation specifies: Read data from stdout and stderr, until end-of-file is reached

                  proc = sub.Popen("psql -h darwin -d main_db".split(),stdin=sub.PIPE,stdout=sub.PIPE)
                  print proc.communicate("select a,b,result from experiment_1412;
                  ")[0]
                  print proc.communicate("select theta,zeta,result from experiment_2099
                  ")[0]
                  

                  这里的问题是第二次,Python 不高兴.的确,他决定在第一次沟通后关闭文件:

                  The problem here is that the second time, Python isn't happy. Indeed, he decided to close the file after the first communicate:

                  Traceback (most recent call last):
                  File "a.py", line 30, in <module>
                      print proc.communicate("select theta,zeta,result from experiment_2099
                  ")[0]
                  File "/usr/lib64/python2.5/subprocess.py", line 667, in communicate
                      return self._communicate(input)
                  File "/usr/lib64/python2.5/subprocess.py", line 1124, in _communicate
                       self.stdin.flush()
                  ValueError: I/O operation on closed file
                  

                  是否允许多次通信?

                  推荐答案

                  我觉得你误解了沟通...

                  I think you misunderstand communicate...

                  http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate

                  communicate 向另一个进程发送一个字符串,然后等待它完成......(就像你说的等待 EOF 监听 stdout & stderror)

                  communicate sends a string to the other process and then waits on it to finish... (Like you said waits for the EOF listening to the stdout & stderror)

                  你应该做的是:

                  proc.stdin.write('message')
                  
                  # ...figure out how long or why you need to wait...
                  
                  proc.stdin.write('message2')
                  

                  (如果您需要获取 stdout 或 stderr,您可以使用 proc.stdout 或 proc.stderr)

                  (and if you need to get the stdout or stderr you'd use proc.stdout or proc.stderr)

                  这篇关于在不破坏管道的情况下与进程多次通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:子进程中的python getoutput()等价物 下一篇:终止正在运行的子进程调用

                  相关文章

                    <legend id='cOHCS'><style id='cOHCS'><dir id='cOHCS'><q id='cOHCS'></q></dir></style></legend>
                      <tfoot id='cOHCS'></tfoot>
                        <bdo id='cOHCS'></bdo><ul id='cOHCS'></ul>

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

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