执行下面的代码时出现错误。问题似乎是map不支持接受多个输入的函数,就像在 python 内置multiprocessing包中一样。但在内置包中,有一个starmap可以解决这个问题。pathos.multiprocessing有相同的吗?
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
if __name__ == '__main__':
b = Bar()
pool = mp.ProcessingPool()
results = pool.map(b.boo, [(12, 3, 456), (8, 9, 10), ('a', 'b', 'cde')])
print(results)
Run Code Online (Sandbox Code Playgroud)
类型错误:boo() 缺少 2 个必需的位置参数:“y”和“z”
按照建议更新 lambda 表达式(不起作用):
if __name__ == '__main__':
b = Bar()
pool = mp.ProcessingPool()
results = …Run Code Online (Sandbox Code Playgroud)