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

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

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

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

        Python Subprocess.Popen 从一个线程

        Python Subprocess.Popen from a thread(Python Subprocess.Popen 从一个线程)
        <tfoot id='Nqyqt'></tfoot>

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

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

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

                  问题描述

                  我正在尝试使用子进程模块和 Popen 在线程内启动rsync".在我调用 rsync 之后,我还需要读取输出.我正在使用通信方法来读取输出.当我不使用线程时,代码运行良好.看来,当我使用线程时,它会挂在通信调用上.我注意到的另一件事是,当我设置 shell=False 时,我在线程中运行时不会从通信中得到任何回报.

                  I'm trying to launch an 'rsync' using subprocess module and Popen inside of a thread. After I call the rsync I need to read the output as well. I'm using the communicate method to read the output. The code runs fine when I do not use a thread. It appears that when I use a thread it hangs on the communicate call. Another thing I've noticed is that when I set shell=False I get nothing back from the communicate when running in a thread.

                  推荐答案

                  您没有提供任何代码供我们查看,但这里有一个与您描述的类似的示例:

                  You didn't supply any code for us to look at, but here's a sample that does something similar to what you describe:

                  import threading
                  import subprocess
                  
                  class MyClass(threading.Thread):
                      def __init__(self):
                          self.stdout = None
                          self.stderr = None
                          threading.Thread.__init__(self)
                  
                      def run(self):
                          p = subprocess.Popen('rsync -av /etc/passwd /tmp'.split(),
                                               shell=False,
                                               stdout=subprocess.PIPE,
                                               stderr=subprocess.PIPE)
                  
                          self.stdout, self.stderr = p.communicate()
                  
                  myclass = MyClass()
                  myclass.start()
                  myclass.join()
                  print myclass.stdout
                  

                  这篇关于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 画布滚动条?)

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

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

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

                            <tbody id='oQO77'></tbody>
                        • <tfoot id='oQO77'></tfoot>

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