[英]How use multiprocessing.Pool.map with iterator and separat input for function
如何将完整的参数传递给 function myfun 并同时传递集合中的相应元素 [1,2,3,4,5]
p=Pool(5)
p.map(myfun(df_A,df_B),[1,2,3,4,5])
如果我以这种方式实现它,function 会获取参数 df_A 和 df_B 但不是集合中的元素
这是 myfun 的示例:
def myfunc(df_A, df_B, e):
do_something
print(df_A.iloc[e],df_A.iloc[e])
e 是集合 [1,2,3,4,5] 的一个元素
您可以考虑这样的事情(可能有更好的方法):
from multiprocessing import Pool
def myfunc(a, b, c):
print(a, b, c)
df_A = 1
df_B = 2
def main():
with Pool() as pool:
pool.starmap(myfunc,[[df_A, df_B, x] for x in range(1, 6)])
if __name__ == '__main__':
main()
Output:
1 2 1
1 2 2
1 2 3
1 2 4
1 2 5
编辑:现在使用星图,因为 myfunc function 签名的知识在我的原始帖子之后可用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.