普遍的答案涉及使用
Manager对象。改编自文档:
from multiprocessing import Process, Managerdef f(d): d[1] += '1' d['2'] += 2if __name__ == '__main__': manager = Manager() d = manager.dict() d[1] = '1' d['2'] = 2 p1 = Process(target=f, args=(d,)) p2 = Process(target=f, args=(d,)) p1.start() p2.start() p1.join() p2.join() print d
输出:
$ python mul.py {1: '111', '2': 6}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)