python併發程式設計-程序之間的資料共享
阿新 • • 發佈:2018-12-20
# from multiprocessing import Manager,Process # def main(dic): # dic['count'] -= 1 # print(dic) # # if __name__ == '__main__': # m = Manager() # dic=m.dict({'count':100}) # p_lst = [] # p = Process(target=main, args=(dic,)) # p.start() # p.join() from multiprocessing import Manager,Process,Lock def main(dic,lock): dic['count'] -= 1 if __name__ == '__main__': m = Manager() l = Lock() dic=m.dict({'count':100}) p_lst = [] for i in range(50): p = Process(target=main,args=(dic,l)) p.start() p_lst.append(p) for i in p_lst: i.join() print('主程序',dic)