Unable to modify global variable in Python

Viewed 38

I am trying to update the value of a variable which is globally declared, from a python function. And I am feeding this function to a Pool.map() method. But I don't see variable getting updated. Please explain what is happening and what is the fix?

from multiprocessing import Pool
a=0
def fun(num):
    global a
    if num==4:
        a=4

if __name__=='__main__':
    pool=Pool()
    pool.map(fun,[1,2,3,4,5,6])
    pool.close()
    pool.join()
    print(a)

Output=0 Expected output = 4

0 Answers
Related