• <small id='5IdEw'></small><noframes id='5IdEw'>

  • <tfoot id='5IdEw'></tfoot>

  • <legend id='5IdEw'><style id='5IdEw'><dir id='5IdEw'><q id='5IdEw'></q></dir></style></legend>

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

        • <bdo id='5IdEw'></bdo><ul id='5IdEw'></ul>

        Python中子进程读取线超时

        Timeout on subprocess readline in Python(Python中子进程读取线超时)
              <legend id='VnieH'><style id='VnieH'><dir id='VnieH'><q id='VnieH'></q></dir></style></legend>
                <bdo id='VnieH'></bdo><ul id='VnieH'></ul>

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

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

                  <tbody id='VnieH'></tbody>

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

                  问题描述

                  我有一个小问题,我不太确定如何解决.这是一个最小的例子:

                  I have a small issue that I'm not quite sure how to solve. Here is a minimal example:

                  scan_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
                  while(some_criterium):
                      line = scan_process.stdout.readline()
                      some_criterium = do_something(line)
                  

                  我想要什么

                  scan_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
                  while(some_criterium):
                      line = scan_process.stdout.readline()
                      if nothing_happens_after_10s:
                          break
                      else:
                          some_criterium = do_something(line)
                  

                  我从子进程中读取了一行并对其进行了处理.如果在固定时间间隔后没有线路到达,我该如何退出?

                  I read a line from a subprocess and do something with it. How can I exit if no line arrived after a fixed time interval?

                  推荐答案

                  感谢大家的回答!

                  我找到了一种方法来解决我的问题,只需使用 select.poll 来查看标准输出.

                  I found a way to solve my problem by simply using select.poll to peek into standard output.

                  import select
                  ...
                  scan_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
                  poll_obj = select.poll()
                  poll_obj.register(scan_process.stdout, select.POLLIN)
                  while(some_criterium and not time_limit):
                      poll_result = poll_obj.poll(0)
                      if poll_result:
                          line = scan_process.stdout.readline()
                          some_criterium = do_something(line)
                      update(time_limit)
                  

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

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

                  相关文档推荐

                  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 画布滚动条?)
                    <tbody id='QgoIq'></tbody>
                  <legend id='QgoIq'><style id='QgoIq'><dir id='QgoIq'><q id='QgoIq'></q></dir></style></legend>
                  • <bdo id='QgoIq'></bdo><ul id='QgoIq'></ul>

                      <tfoot id='QgoIq'></tfoot>

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

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