系统相关
首页 > 系统相关> > python基础一 day38 进程间的数据共享

python基础一 day38 进程间的数据共享

作者:互联网

 

 

# 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)

 

标签:__,count,day38,python,数据共享,dic,Process,lst,main
来源: https://www.cnblogs.com/wang-tan/p/11439922.html