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多进程间通信_第1张图片

 

你可能感兴趣的:(python多进程间通信)