Manager模块:
from multiprocessing import Manager,Process def ma(arg,dic): dic[arg] = 100 if __name__ == ‘__main__‘: m = Manager() dic = m.dict() # 进程之间数据共享 for i in range(10): p = Process(target=ma,args=(i,dic)) p.start() p.join() print(dic)
{0: 100, 1: 100, 2: 100, 3: 100, 4: 100, 5: 100, 6: 100, 7: 100, 8: 100, 9: 100}
Manager模块/进程的数据共享