I am having some trouble using a tuple globally with the multiprocessing class.
I have a code as produced below:
from multiprocessing import Pool
if __name__ == '__main__':
jj = ()
def f(x):
global jj
jj += (x*x,)
# Section A
#for ii in range(20):
# f(ii)
#print (jj)
# Section B
pool = Pool(processes=4)
pool.map(f, range(20))
pool.join()
print (jj)
If I run section only B, I get the tuple jj as an empty tuple. However, if I run only section A, I get a tuple of length 20.
Why is that so?