python多进程间通信代码实例

python多进程间通信代码实例,第1张

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

执行后的效果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/3253325.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-04
下一篇 2022-10-04

发表评论

登录后才能评论

评论列表(0条)

保存