网络编程
位置:首页>> 网络编程>> Python编程>> python多进程间通信代码实例

python多进程间通信代码实例

作者:科技改变未来☆  发布时间:2023-10-06 20:22:17 

标签:python,多,进程,通信

这篇文章主要介绍了python多进程间通信代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

这里使用pipe代码如下:


import time
from multiprocessing import Process
import multiprocessing

class D:
 @staticmethod
 def test(pipe):
   while True:
     for i in range(10):
       pipe.send(i)
      time.sleep(2)

@staticmethod
 def test2(pipe):
   while True:print('test2 value:%s' % pipe.recv())
     time.sleep(2)

if __name__ == '__main__':
 pipe = multiprocessing.Pipe()
 p = Process(target=D.test2,args=(pipe[0],))
 p2 = Process(target=D.test,args=(pipe[1],))

p.start()
 p2.start()

执行后的效果:

python多进程间通信代码实例

来源:https://www.cnblogs.com/codeDevotee/p/11553556.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com