I am trying to understand how Pool()
and Manager()
can be combined in Python's multiprocessing library for having shared objects between the individual worker processes. In my example, I would like to have a shared list input_list
, which should be accessable for all worker processes:
from multiprocessing import Pool, Manager
def f(x):
input_list.append(x)
return x**2
if __name__ == '__main__':
manager = Manager()
input_list = manager.list()
with Pool(processes=3) as pool:
results = pool.map(f, range(10))
print(input_list)
However, I get a NameError: name 'input_list' is not defined
. Any idea why input_list
is not recognized as a shared object?