I'm having a problem getting different return values from a pool.map
call. Im running this simplified example on a macbook, in a jupyter notebook with python 3.9:
import multiprocessing as mp
import numpy as np
def gen_random_list(num):
print(f"Num: {num}\n")
ret_list = np.random.randint(0, 5, size=3).tolist()
return ret_list
with mp.Pool() as pool:
results = []
results = pool.map(gen_random_list, range(4))
print(results)
I keep getting the same list back for each call to gen_random_list
. The complete output is this:
Num: 0
Num: 1
Num: 2
Num: 3
[[0, 3, 2], [0, 3, 2], [0, 3, 2], [0, 3, 2]]
Does anyone know why every call to gen_random_list
is returning the same values (in this run: [0, 3, 2]
)? And how do I fix this so I get a different random list back each time?
Thanks Brett