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

  • <tfoot id='sJc6m'></tfoot>

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

    1. <legend id='sJc6m'><style id='sJc6m'><dir id='sJc6m'><q id='sJc6m'></q></dir></style></legend>
    2. <i id='sJc6m'><tr id='sJc6m'><dt id='sJc6m'><q id='sJc6m'><span id='sJc6m'><b id='sJc6m'><form id='sJc6m'><ins id='sJc6m'></ins><ul id='sJc6m'></ul><sub id='sJc6m'></sub></form><legend id='sJc6m'></legend><bdo id='sJc6m'><pre id='sJc6m'><center id='sJc6m'></center></pre></bdo></b><th id='sJc6m'></th></span></q></dt></tr></i><div id='sJc6m'><tfoot id='sJc6m'></tfoot><dl id='sJc6m'><fieldset id='sJc6m'></fieldset></dl></div>
      1. Python子进程调用挂起

        Python subprocess call hangs(Python子进程调用挂起)
              <tbody id='H8o9E'></tbody>

            <tfoot id='H8o9E'></tfoot>
              <legend id='H8o9E'><style id='H8o9E'><dir id='H8o9E'><q id='H8o9E'></q></dir></style></legend>

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

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

                  <bdo id='H8o9E'></bdo><ul id='H8o9E'></ul>
                • 本文介绍了Python子进程调用挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Python 版本:2.6.7我在执行 18 次的 for 循环中有以下 subprocess.call,但是,该进程在第 19 次循环中不断挂起:

                  Python version: 2.6.7 I have the following subprocess.call within a for loop which is exectuted 18 times, however, the process constantly hangs on the 19th loop:

                  if config.get_bool_option(NAME, 'exclude_generated_code', True):
                              for conf in desc.iter_configs():
                                  for gen in desc.iter_generators(conf):
                                      generator.initialize_generated_path(gen, desc)
                                      for genpath in gen.generated_path:
                                          os.rename(cov_file, cov_file+'.temp')
                                          exclude = ['lcov']
                                          exclude += ['-r', cov_file+'.temp', '"'+genpath+'/*"']
                                          exclude += ['-o', cov_file]
                                          if verbose: Tracer.log.info("Running "+ ' '.join(exclude))
                                          try:
                                              subprocess.call(' '.join(exclude), stdout=out, stderr=out, shell=True)
                                          except subprocess.CalledProcessError, e:
                                          if verbose: Tracer.log.info("TESTING: Got Exception 
                  ") 
                  

                  控制台输出如下:

                  Running lcov -r /remote/XXXXXX/coverage.19.temp "/remote/XXXXXX/xml/2009a/generated/*" -o /remote/XXXXX/gcov/coverage.19
                  

                  由于我对python脚本不是很熟悉,所以我只是在这里徘徊是否我做错了什么......我怀疑某个地方出现了死锁......

                  Since I am not very familiar with python scripts, I just wandered whether I am doing something wrong here...I suspect a deadlock somewhere..

                  stdout,stderr = process.communicate()会处理这些问题吗?

                  请专家解答 subprocess.call 在哪些情况下会挂起?非常感谢

                  Any expert answer on in which cases would the subprocess.call hang please? Thanks very much

                  推荐答案

                  在使用子进程时,我倾向于这样做:

                  When using subprocess, I tend to do something like this:

                  is_running = lambda: my_process.poll() is None
                  
                  my_process = subprocess.Popen(' '.join(exclude), 
                                                stdout=subprocess.PIPE, 
                                                stderr=subprocess.PIPE,
                                                shell=True)
                  
                  # Grab all the output from stdout and stderr and log it
                  while is_running():
                      rlist, wlist, xlist = select.select([my_process.stdout, my_process.stderr], [], [], 1)
                  
                  # Log stdout, but don't spam the log
                  if my_process.stdout in rlist and verbose:
                      # Adjust the number of bytes read however you like, 1024 seems to work 
                      # pretty well for me. 
                      Tracer.log.debug(my_process.stdout.read(1024))
                  
                  # Log stderr, always
                  if my_process.stderr in rlist:
                      # Same as with stdout, adjust the bytes read as needed.
                      Tracer.log.error(my_process.stderr.read(1024))
                  

                  过去,我看到标准输出的东西只是在我的日志中转储了一堆空行,这就是我在调试级别记录的原因.这会在开发过程中打印到我的日志中,但从未在生产中写入,因此我可以安全地将其留在代码中进行调试,而不会将垃圾放入日志中.

                  I've seen the stdout stuff just dump a bunch of empty lines in my logs in the past, which is why I log that at the debug level. That prints to my logs during the development, but never gets written in production, so I can safely leave it in the code for debugging without putting garbage in their logs.

                  希望这有助于揭示您的程序挂起的位置以及导致挂起的原因.

                  Hopefully, this can help expose just where your program is hanging and what's causing it.

                  这篇关于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='fXJtM'></tbody>

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

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

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