Python常用基础语法知识点大全(python中基本语法)
356
2022-08-23
day11_进程之间的数据共享(m个进程共享n个互斥资源)
1.#__author__ = 'DouYunQian' #coding=utf-8 from multiprocessing import Process import time from multiprocessing import queues import multiprocessing def f(i,l): # l.append(i) l.put(i) # time.sleep(2) print("Say:",i,"***",l.qsize()) if __name__=="__main__": # l=[] l=queues.Queue(10,ctx=multiprocessing) for i in range(10): t=Process(target=f,args=(i,l)) t.daemon=False #这是等待的意思 t.start() print("End")2.代码2:from multiprocessing import Process from multiprocessing import Array def f1(i,array): array[i]=i+100 for item in array: print(item) if __name__=="__main__": c=Array("i",10) #指定类型和最大个数 for i in range(10): p=Process(target=f1,args=(i,c)) p.start() p.join() print("End")3.代码3:from multiprocessing import Process from multiprocessing import Manager def f1(i,di): di[i]=i+100 if __name__=="__main__": c=Manager() dic=c.dict() for i in range(10): t=Process(target=f1,args=(i,dic,)) t.start() t.join()#此处如果不加join会报错,报错如下: print("End") File "C:\Python34\lib\multiprocessing\managers.py", line 715, in _connect conn = self._Client(self._token.address, authkey=self._authkey) File "C:\Python34\lib\multiprocessing\connection.py", line 494, in Client c = PipeClient(address) File "C:\Python34\lib\multiprocessing\connection.py", line 697, in PipeClient _winapi.WaitNamedPipe(address, 1000) FileNotFoundError: [WinError 2] The system cannot find the file specified
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~