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

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

        如何使用 python 2.7.6 使 subprocess.call 超时?

        时间:2023-07-21
        <legend id='FWnUE'><style id='FWnUE'><dir id='FWnUE'><q id='FWnUE'></q></dir></style></legend>
            <bdo id='FWnUE'></bdo><ul id='FWnUE'></ul>

                <tbody id='FWnUE'></tbody>

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

              <i id='FWnUE'><tr id='FWnUE'><dt id='FWnUE'><q id='FWnUE'><span id='FWnUE'><b id='FWnUE'><form id='FWnUE'><ins id='FWnUE'></ins><ul id='FWnUE'></ul><sub id='FWnUE'></sub></form><legend id='FWnUE'></legend><bdo id='FWnUE'><pre id='FWnUE'><center id='FWnUE'></center></pre></bdo></b><th id='FWnUE'></th></span></q></dt></tr></i><div id='FWnUE'><tfoot id='FWnUE'></tfoot><dl id='FWnUE'><fieldset id='FWnUE'></fieldset></dl></div>
                  <tfoot id='FWnUE'></tfoot>
                  本文介绍了如何使用 python 2.7.6 使 subprocess.call 超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这可能已经被问过了,但我在使用 python 2.7 时找不到任何关于 subprocess.call 超时的信息

                  This has probably been asked but I cannot find anything regarding a subprocess.call timeout when using python 2.7

                  推荐答案

                  我一直使用 2.7 完成超时的一个简单方法是使用 subprocess.poll()time.sleep() 延迟.这是一个非常基本的例子:

                  A simple way I've always done timeouts with 2.7 is utilizing subprocess.poll() alongside time.sleep() with a delay. Here's a very basic example:

                  import subprocess
                  import time
                  
                  x = #some amount of seconds
                  delay = 1.0
                  timeout = int(x / delay)
                  
                  args = #a string or array of arguments
                  task = subprocess.Popen(args)
                  
                  #while the process is still executing and we haven't timed-out yet
                  while task.poll() is None and timeout > 0:
                       #do other things too if necessary e.g. print, check resources, etc.
                       time.sleep(delay)
                       timeout -= delay
                  

                  如果您设置 x = 600,那么您的超时将达到 10 分钟.而 task.poll() 会查询进程是否已经终止.time.sleep(delay) 在这种情况下会休眠 1 秒,然后将超时时间减 1 秒.您可以随心所欲地玩弄这部分,但基本概念始终相同.

                  If you set x = 600, then your timeout would amount to 10 minutes. While task.poll() will query whether or not the process has terminated. time.sleep(delay) will sleep for 1 second in this case, and then decrement the timeout by 1 second. You can play around with that part to your heart's content, but the basic concept is the same throughout.

                  希望这会有所帮助!

                  subprocess.poll() https://docs.python.org/2/library/subprocess.html#popen-objects

                  这篇关于如何使用 python 2.7.6 使 subprocess.call 超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在其默认程序中启动文件,然后在脚本完成时关闭它? 下一篇:Python3子进程通信示例

                  相关文章

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

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

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