相关疑难解决方法(0)

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

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

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

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

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

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()
Run Code Online (Sandbox Code Playgroud)

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

python multiprocessing progress-bar tqdm

67
推荐指数
7
解决办法
4万
查看次数

使用tqdm与current.futures?

我有一个多线程函数,我想要一个使用状态栏tqdm。有没有一种简单的方法可以显示状态栏ThreadPoolExecutor?正是并行化部分使我感到困惑。

import concurrent.futures

def f(x):
    return f**2

my_iter = range(1000000)

def run(f,my_iter):
    with concurrent.futures.ThreadPoolExecutor() as executor:
        function = list(executor.map(f, my_iter))
    return results

run(f, my_iter) # wrap tqdr around this function?
Run Code Online (Sandbox Code Playgroud)

python concurrent.futures tqdm

23
推荐指数
3
解决办法
3180
查看次数