I'm the pathos
作者。pathos
比starmap
,并且并不真正需要它。它解决池中的多个参数的方式与内置的完全相同map
does.
>>> import pathos.multiprocessing as mp
>>> class Bar:
... def foo(self, name):
... return len(str(name))
... def boo(self, x, y, z):
... sum = self.foo(x)
... sum += self.foo(y)
... sum += self.foo(z)
... return sum
...
>>> b = Bar()
>>> pool = mp.ProcessingPool()
>>> f = lambda x: b.boo(*x)
>>> results = pool.map(f, [(12, 3, 456), (8, 9, 10), ('a', 'b', 'cde')])
>>> results
[6, 4, 5]
>>> results = pool.map(b.boo, [12, 9, 'a'], [3, 9, 'b'], [456, 10, 'cde'])
>>> results
[6, 4, 5]
>>> results = map(b.boo, [12, 9, 'a'], [3, 9, 'b'], [456, 10, 'cde'])
>>> list(results)
[6, 4, 5]
>>>
所以,本质上,starmap
是不必要的。然而,由于它最近被添加到标准中Pool
接口在multiprocessing
在某些版本的 python 中,它可能应该更加突出pathos
。请注意,已经可以获得“增强”版本starmap
from pathos
如果你喜欢。
>>> import pathos
>>> mp = pathos.helpers.mp
>>> p = mp.Pool()
>>> p.starmap
<bound method Pool.starmap of <multiprocess.pool.Pool object at 0x1038684e0>>
>>>