I have a following simple code
from multiprocessing import Pool
x = []
def func(a):
print(x,a)
def main():
a = [1,2,3,4,5]
pool = Pool(1)
global x
x = [1,2,3,4]
ans = pool.map(func,a)
print(x)
It gives me the result
[] 1
[] 2
[] 3
[] 4
[] 5
[1, 2, 3, 4]
I expected the result to reflects the change in global variable x.
Which seems that the changed in global variable x is not updated before the pool call. I would like to ask what is the cause of this?
xwith pool in any way here.Which seems that the global variable x is not used in the pool at all: This is because x is not used in pool at all. This is what I am getting at. Maybe your wording is misleading to your problem.