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

    1. <legend id='f7y8C'><style id='f7y8C'><dir id='f7y8C'><q id='f7y8C'></q></dir></style></legend>

      <tfoot id='f7y8C'></tfoot>
        <bdo id='f7y8C'></bdo><ul id='f7y8C'></ul>

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

      2. Python 3.4 多处理递归 Pool.map()

        时间:2023-05-26
        <i id='CI25o'><tr id='CI25o'><dt id='CI25o'><q id='CI25o'><span id='CI25o'><b id='CI25o'><form id='CI25o'><ins id='CI25o'></ins><ul id='CI25o'></ul><sub id='CI25o'></sub></form><legend id='CI25o'></legend><bdo id='CI25o'><pre id='CI25o'><center id='CI25o'></center></pre></bdo></b><th id='CI25o'></th></span></q></dt></tr></i><div id='CI25o'><tfoot id='CI25o'></tfoot><dl id='CI25o'><fieldset id='CI25o'></fieldset></dl></div>
        1. <legend id='CI25o'><style id='CI25o'><dir id='CI25o'><q id='CI25o'></q></dir></style></legend>

            <tfoot id='CI25o'></tfoot>
              <tbody id='CI25o'></tbody>
            • <bdo id='CI25o'></bdo><ul id='CI25o'></ul>
              • <small id='CI25o'></small><noframes id='CI25o'>

                  本文介绍了Python 3.4 多处理递归 Pool.map()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在 Ubuntu 14.04 上使用 Python 3.4 进行开发.我试图做递归 Pool.map().在我调用 g() 之后,它挂在那里并且永远不会返回.

                  I'm developing with Python 3.4 on Ubuntu 14.04. I was trying to do recursive Pool.map(). After I invoke g(), it hangs there and never returns.

                  import multiprocessing as mp
                  
                  pool = mp.Pool()
                  
                  def d(x):
                      return x / 2.0
                  
                  
                  def f(x):
                      w = pool.map(d, x)
                      return w
                  
                  def g():
                      v = pool.map(f, [[1, 2], [3, 4]])
                  
                      print(v)
                  

                  推荐答案

                  这是不可能的.Pool 对象本身不能安全地在进程之间共享,因此不能在 fg 中使用同一个池.即使您可以这样做,也会很快导致挂起,因为您的池仅限于 cpu_count() 个并发工作人员.一旦你开始递归地创建更多的工人,你最终会得到超过 cpu_count() 个工人,这将永远无法完成;正在运行的工作人员将等待池中排队的任务,但排队的任务将永远无法启动,因为正在运行的任务正在等待.所以你最终陷入僵局.简而言之:不要尝试这样做.

                  This isn't possible. The Pool object itself can't safely be shared between processes, so the same pool can't be used in both f and g. Even if you could do this, you'd quickly cause a hang, because your pool is limited to cpu_count() concurrent workers. Once you start creating more workers recursively, you'll end up with more than cpu_count() workers, which will never be able to finish; the running workers would be waiting on tasks that are queued up in the pool, but the queued up tasks won't ever be able to start because the running tasks are waiting. So you end up deadlocked. In short: don't try to do this.

                  这篇关于Python 3.4 多处理递归 Pool.map()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:是否可以从 Scrapy spider 运行另一个蜘蛛? 下一篇:多处理中的error_callback.Python 2中的池apply_async?

                  相关文章

                  最新文章

                  <legend id='MRYmr'><style id='MRYmr'><dir id='MRYmr'><q id='MRYmr'></q></dir></style></legend>
                  <tfoot id='MRYmr'></tfoot>
                  1. <small id='MRYmr'></small><noframes id='MRYmr'>

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

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