I wouldd like to use multiprocessing pool
to access, read, and modify a variable in python. The processes are completely separate, but have to access the same variable. This would be easily done with pointers
in C
, but how do I do it in python?
For example, I have done this:
import multiprocessing as mp
import time
a=3
def one(arg):
time.sleep(2*arg[1])
print(arg)
arg[0]+=1
print(arg[0])
return arg[0]
if __name__ == '__main__':
with mp.Pool(processes=2) as pool:
print(pool.map(one,[[a,1],[a,2]]))
But it returns
[3, 1]
4
[3, 2]
4
[4, 4]
Instead of [4,5]
.