当前位置: 移动技术网 > IT编程>脚本编程>Python > 进程间通信

进程间通信

2020年04月30日  | 移动技术网IT编程  | 我要评论

艺术照女人殖生器图片,庶出庶出19楼,卓琳爱尔

一、通过queue方式进行通信

 1 from multiprocessing import process,queue,pipe
 2 def f(q):
 3     q.put([42,2,'hello'])
 4 
 5 if __name__=='__main__':
 6     q=queue()
 7     p_list=[]
 8 
 9     for i in range(3):
10         p=process(target=f,args=(q,))
11         p_list.append(p)
12         p.start()
13 
14     print(q.get())
15     print(q.get())
16     print(q.get())

二、通过pipe方式通信 

 1 def f(conn):
 2     conn.send([42,none,'hello'])
 3     conn.send('love')
 4     print(conn.recv())
 5     conn.close()
 6 if __name__=='__main__':
 7     parent_conn,child_conn=pipe()
 8     p=process(target=f,args=(child_conn,))
 9     p.start()
10     print(parent_conn.recv())
11     print(parent_conn.recv())
12     parent_conn.send('你好')
13     p.join()

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网