首页 > 解决方案 > 进度条starmap_async多处理python

问题描述

我已经构建了一个多处理器来加速进程(300.000 个参数),但是如果它显示类似的进度条会很好,这样我就可以跟踪进度。我在 stackoverflow 上搜索了一个合适的解决方案,但是找不到类似的问题。是否可以在 starmap_async 上使用进度方法?如果没有,有什么好的选择?

import multiprocessing as mp

def origins(G, x, y):
  return ox.get_nearest_node(G, (y, x))

x = [buildings.geometry[i].centroid.y for i in list(range(len(buildings)))]
y = [buildings.geometry[i].centroid.y for i in list(range(len(buildings)))]
params = ((G, orig, dest) for orig, dest in zip(y, x))

# create a pool of worker processes
pool = mp.Pool(4)

# map the function/parameters to the worker processes
sma = pool.starmap_async(origins, params)

# get the results, close the pool, wait for worker processes to all exit
routes = sma.get()
pool.close()
pool.join()

有人可以帮我吗?

标签: pythonmultiprocessingprogress

解决方案


推荐阅读