是否有一个简单的基于进程的python并行映射?

是否有一个简单的基于进程的python并行映射?,第1张

是否有一个简单的基于进程的python并行映射

我似乎您需要的是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 submits

to 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))


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5652947.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存