Return Value Of Multiprocessing And Extract It As An Input Of Another Function In Python
from multiprocessing import Pool a=[1,2,3,4,5,6] def func1(a): return a**2 def func2(a): x= np.zeros(1) for i in a: x += i return x if __name__ == '__main_
Solution 1:
Maybe you are looking for something in this direction:
import multiprocessing as mp
import numpy as np
def func1(n):
return n ** 2
def func2(a):
pool = mp.Pool(mp.cpu_count())
results = pool.map(func1, a)
pool.close()
pool.join()
print(results)
# [1, 4, 9, 16, 25, 36]
x = np.sum(results)
return x
if __name__ == "__main__":
a = [1, 2, 3, 4, 5, 6]
out = func2(a)
print(out)
# 91
Post a Comment for "Return Value Of Multiprocessing And Extract It As An Input Of Another Function In Python"