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:"
#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 【本文转自:香港大带宽服务器 http://www.558idc.com/st.html 欢迎留下您的宝贵建议】