I am trying to run a multiprocessing function and store its output in an array somehow, but can not seem to find a way to do so. This is what I have got so far:
resultsAr = []
inputData = [a,b,c,d]#THIS ARRAY CONTAINS DATA
def function(data):
values = [some_Number_1, some_Number_2]
resultsAr.append(values)
print ('Values = ', values) #THIS WORKS - THE CORRECT VALUES ARE PRINTED
print ('resultsAr = ', resultsAr) #WORKS AS WELL
def parallel_run(function, inputData): #a function that runs in multiple processors
cpu_no = 4
if len(inputData) < cpu_no:
cpu_no = len(inputData)
p = multiprocessing.Pool(cpu_no)
p.starmap_async(function, inputData, chunksize=1)
p.close()
p.join()
print ('resultsAr = ', resultsAr) # THIS PRINTS OUT AN EMPTY ARRAY!
parallel_run(function, inputData)