python多进程间通信

匿名 (未验证) 提交于 2019-12-02 22:51:30

这里使用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()

执行后的效果:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!