你可以用
tqdm周围
executor,如下跟踪进度:
list(tqdm(executor.map(f, iter), total=len(iter))
这是您的示例:
import time import concurrent.futuresfrom tqdm import tqdmdef f(x): time.sleep(0.001) # to visualize the progress return x**2def run(f, my_iter): with concurrent.futures.ThreadPoolExecutor() as executor: results = list(tqdm(executor.map(f, my_iter), total=len(my_iter))) return resultsmy_iter = range(100000)run(f, my_iter)
结果是这样的:
16%|██▏| 15707/100000 [00:00<00:02, 31312.54it/s]
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)