python多程序間通訊程式碼例項
阿新 • • 發佈:2020-01-09
這篇文章主要介紹了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()執行後的效果:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。
