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

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

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

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

      分析 python 多处理池

      时间:2023-08-06
    1. <small id='o5EBv'></small><noframes id='o5EBv'>

        • <bdo id='o5EBv'></bdo><ul id='o5EBv'></ul>

          <tfoot id='o5EBv'></tfoot>

              <legend id='o5EBv'><style id='o5EBv'><dir id='o5EBv'><q id='o5EBv'></q></dir></style></legend>

            • <i id='o5EBv'><tr id='o5EBv'><dt id='o5EBv'><q id='o5EBv'><span id='o5EBv'><b id='o5EBv'><form id='o5EBv'><ins id='o5EBv'></ins><ul id='o5EBv'></ul><sub id='o5EBv'></sub></form><legend id='o5EBv'></legend><bdo id='o5EBv'><pre id='o5EBv'><center id='o5EBv'></center></pre></bdo></b><th id='o5EBv'></th></span></q></dt></tr></i><div id='o5EBv'><tfoot id='o5EBv'></tfoot><dl id='o5EBv'><fieldset id='o5EBv'></fieldset></dl></div>
                <tbody id='o5EBv'></tbody>
              • 本文介绍了分析 python 多处理池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试在多处理池中的每个进程上运行 cProfile.runctx(),以了解我的源中的多处理瓶颈是什么.这是我正在尝试做的一个简化示例:

                I'm trying to run cProfile.runctx() on each process in a multiprocessing pool, to get an idea of what the multiprocessing bottlenecks are in my source. Here is a simplified example of what I'm trying to do:

                from multiprocessing import Pool
                import cProfile
                
                def square(i):
                    return i*i
                
                def square_wrapper(i):
                    cProfile.runctx("result = square(i)",
                        globals(), locals(), "file_"+str(i))
                    # NameError happens here - 'result' is not defined.
                    return result
                
                if __name__ == "__main__":
                    pool = Pool(8)
                    results = pool.map_async(square_wrapper, range(15)).get(99999)
                    print results
                

                不幸的是,尝试在分析器中执行result = square(i)"不会影响调用范围内的result".我怎样才能在这里完成我想要做的事情?

                Unfortunately, trying to execute "result = square(i)" in the profiler does not affect 'result' in the scope it was called from. How can I accomplish what I am trying to do here?

                推荐答案

                试试这个:

                def square_wrapper(i):
                    result = [None]
                    cProfile.runctx("result[0] = square(i)", globals(), locals(), "file_%d" % i)
                    return result[0]
                

                这篇关于分析 python 多处理池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:将 defaultdict 与多处理一起使用? 下一篇:如何使用 Python 多处理池处理 tarfile?

                相关文章

                最新文章

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

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

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