
我似乎您需要的是multiprocessing.Pool()中的map方法:
map(func,iterable [,chunksize])
A parallel equivalent of the map() built-in function (it supports onlyone iterable argument though). It blocks till the result is ready.This method chops the iterable into a number of chunks which it submitsto the
process pool as separate tasks. The (approximate) size of these chunks
can be
specified by setting chunksize to a positive integ
例如,如果要映射此功能:
def f(x): return x**2
到range(10),可以使用内置的map()函数:
map(f, range(10))
或使用multiprocessing.Pool()对象的方法map():
import multiprocessingpool = multiprocessing.Pool()print pool.map(f, range(10))
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)