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

  • <legend id='nL8iu'><style id='nL8iu'><dir id='nL8iu'><q id='nL8iu'></q></dir></style></legend>

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

      1. 多处理 AsyncResult.get() 在 Python 3.7.2 中挂起,但在

        时间:2023-05-26

        <tfoot id='yy3jY'></tfoot>
        • <small id='yy3jY'></small><noframes id='yy3jY'>

              • <bdo id='yy3jY'></bdo><ul id='yy3jY'></ul>
                <i id='yy3jY'><tr id='yy3jY'><dt id='yy3jY'><q id='yy3jY'><span id='yy3jY'><b id='yy3jY'><form id='yy3jY'><ins id='yy3jY'></ins><ul id='yy3jY'></ul><sub id='yy3jY'></sub></form><legend id='yy3jY'></legend><bdo id='yy3jY'><pre id='yy3jY'><center id='yy3jY'></center></pre></bdo></b><th id='yy3jY'></th></span></q></dt></tr></i><div id='yy3jY'><tfoot id='yy3jY'></tfoot><dl id='yy3jY'><fieldset id='yy3jY'></fieldset></dl></div>
                  <tbody id='yy3jY'></tbody>
                • <legend id='yy3jY'><style id='yy3jY'><dir id='yy3jY'><q id='yy3jY'></q></dir></style></legend>
                  本文介绍了多处理 AsyncResult.get() 在 Python 3.7.2 中挂起,但在 3.6 中没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试将一些代码从 Python 3.6 移植到 Windows 10 上的 Python 3.7.在 AsyncResult 上调用 .get() 时,我看到多处理代码挂起目的.有问题的代码要复杂得多,但我已将其归结为类似于以下程序的代码.

                  I'm trying to port some code from Python 3.6 to Python 3.7 on Windows 10. I see the multiprocessing code hang when calling .get() on the AsyncResult object. The code in question is much more complicated, but I've boiled it down to something similar to the following program.

                  import multiprocessing
                  
                  
                  def main(num_jobs):
                      num_processes = max(multiprocessing.cpu_count() - 1, 1)
                      pool = multiprocessing.Pool(num_processes)
                  
                      func_args = []
                      results = []
                  
                      try:
                          for num in range(num_jobs):
                              args = (1, 2, 3)
                              func_args.append(args)
                              results.append(pool.apply_async(print, args))
                  
                          for result, args in zip(results, func_args):
                              print('waiting on', args)
                              result.get()
                      finally:
                          pool.terminate()
                          pool.join()
                  
                  
                  if __name__ == '__main__':
                      main(5)
                  

                  此代码也在 Python 2.7 中运行.出于某种原因,对 get() 的第一次调用在 3.7 中挂起,但在其他版本上一切正常.

                  This code also runs in Python 2.7. For some reason the first call to get() hangs in 3.7, but everything works as expected on other versions.

                  推荐答案

                  我认为这是 Python 3.7.2 中描述的回归 这里.它似乎只在 virtualenv 中运行时影响用户.

                  I think this is a regression in Python 3.7.2 as described here. It seems to only affect users when running in a virtualenv.

                  暂时您可以通过执行在此错误线程的评论中描述的操作来解决它.

                  import _winapi
                  import multiprocessing.spawn
                  multiprocessing.spawn.set_executable(_winapi.GetModuleFileName(0))
                  

                  这将强制子进程使用 real python.exe 而不是 virtualenv 中的那个生成.因此,如果您使用 PyInstaller 将内容捆绑到 exe 中,这可能不合适,但在使用本地 Python 安装从 CLI 运行时,它可以正常工作.

                  That will force the subprocesses to spawn using the real python.exe instead of the one that's in the virtualenv. So, this may not be suitable if you're bundling things into an exe with PyInstaller, but it works OK when running from the CLI with local Python installation.

                  这篇关于多处理 AsyncResult.get() 在 Python 3.7.2 中挂起,但在 3.6 中没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将 Python Twisted 与多处理混合使用? 下一篇:将 asyncio 与多处理结合起来会出现什么样的问题

                  相关文章

                  最新文章

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

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