多线程之Manager实现进程间数据的共享与修改
from multiprocessing import Process,Manager
import os,time
def f(d,l):
d[os.getpid()]=os.getpid()
l.append(os.getpid())
print (d)
print (l)
if __name__=='__main__':
with Manager() as manager:
d=manager.dict()
l=manager.list()
res = []
for i in range(10):
p=Process(target=f,args=(d,l))
p.start()
res.append(p)
for p in res:
p.join()
print (d)
print (l)