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

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

  1. <tfoot id='QOSr7'></tfoot>

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

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

    1. 多处理:使用 tqdm 显示进度条

      时间:2023-05-27
        <bdo id='3egh2'></bdo><ul id='3egh2'></ul>

            <tfoot id='3egh2'></tfoot>

            <small id='3egh2'></small><noframes id='3egh2'>

            <legend id='3egh2'><style id='3egh2'><dir id='3egh2'><q id='3egh2'></q></dir></style></legend>
              <tbody id='3egh2'></tbody>

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

                问题描述

                限时送ChatGPT账号..

                为了使我的代码更pythonic"和更快,我使用多处理"和一个映射函数来发送它a)函数和b)迭代范围.

                To make my code more "pythonic" and faster, I use "multiprocessing" and a map function to send it a) the function and b) the range of iterations.

                植入的解决方案(即直接在范围 tqdm.tqdm(range(0, 30)) 上调用 tqdm)不适用于多处理(如下面的代码所示).

                The implanted solution (i.e., call tqdm directly on the range tqdm.tqdm(range(0, 30)) does not work with multiprocessing (as formulated in the code below).

                进度条显示从0到100%(python读取代码时?)但并不表示map函数的实际进度.

                The progress bar is displayed from 0 to 100% (when python reads the code?) but it does not indicate the actual progress of the map function.

                如何显示进度条,指示地图"功能在哪一步?

                from multiprocessing import Pool
                import tqdm
                import time
                
                def _foo(my_number):
                   square = my_number * my_number
                   time.sleep(1)
                   return square 
                
                if __name__ == '__main__':
                   p = Pool(2)
                   r = p.map(_foo, tqdm.tqdm(range(0, 30)))
                   p.close()
                   p.join()
                

                欢迎任何帮助或建议...

                Any help or suggestions are welcome...

                推荐答案

                找到的解决方案:小心!由于多处理,估计时间(每个循环的迭代次数、总时间等)可能不稳定,但进度条运行良好.

                Solution Found : Be careful! Due to multiprocessing, estimation time (iteration per loop, total time, etc.) could be unstable, but the progress bar works perfectly.

                注意:Pool 的上下文管理器仅适用于 Python 3.3 版

                Note: Context manager for Pool is only available from Python version 3.3

                from multiprocessing import Pool
                import time
                from tqdm import *
                
                def _foo(my_number):
                   square = my_number * my_number
                   time.sleep(1)
                   return square 
                
                if __name__ == '__main__':
                    with Pool(processes=2) as p:
                        max_ = 30
                        with tqdm(total=max_) as pbar:
                            for i, _ in enumerate(p.imap_unordered(_foo, range(0, max_))):
                                pbar.update()
                

                这篇关于多处理:使用 tqdm 显示进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:pandas 多处理应用 下一篇:与多处理错误的另一个混淆,“模块"对象没

                相关文章

                最新文章

                  • <bdo id='NulfD'></bdo><ul id='NulfD'></ul>
                  <legend id='NulfD'><style id='NulfD'><dir id='NulfD'><q id='NulfD'></q></dir></style></legend>
                1. <small id='NulfD'></small><noframes id='NulfD'>

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