I have a script that all my workers updates different dictionary in a Manager list. My question is: when one worker is writing the list, will the others wait for it, or all worker can update the list at the same time?
Here is my code:
from multiprocessing import Process, Manager
def worker(x, i, *args):
sub_l = x[i]
sub_l[i] = i
x[i] = sub_l
if __name__ == '__main__':
manager = Manager()
num = 4
x = manager.list([{}]*num)
p = []
for i in range(num):
p.append(Process(target=worker, args=(x, i)))
p[i].start()
for i in range(5):
p[i].join()
print x
I only need all my workers to run separately, and update different global variables. I kind of think using manager.list is an over kill, but not sure if there is other way to do this.