I use the code below to use multiple cores of CPUs to calculate a function (it is an image processing function). However, when the process is finished, the returned value is an object
. I expect to see a NumPy array. Any suggestion is appreciated.
import datetime
from multiprocessing import Process, current_process
import sys
...
def my_function(ImgDir, MaskDir, False, True):
...
All_numpy_arrays = np.dstack(foregrounds)
return All_numpy_arrays
if __name__ == '__main__':
worker_count = 6
worker_pool = []
p = None
for _ in range(worker_count):
result = Process(target=my_function,
args=(ImgDir, MaskDir, False, True))
result.start()
worker_pool.append(result)
for result in worker_pool:
result.join()
# Here I have another script that requires the *result* be a NumPy array
If it helps, I use Ubuntu 20.04
and python 3.8
.