python3 通过队列实现进程间的通信

# coding:utf-8
import time
from multiprocessing import Process, Queue


def func1(q):
    q.put("2orange")


def func2(q):
    print("func2 start...")
    print(q.get())


if __name__ == '__main__':
    que = Queue()
    que.put("1apple")
    p1 = Process(target=func1, args=(que,))
    p2 = Process(target=func2, args=(que,))
    p1.start()
    p2.start()
    time.sleep(1)
    print(que.get())


执行结果:
# func2 start... # 1apple # 2orange

猜你喜欢

转载自www.cnblogs.com/lilyxiaoyy/p/10970879.html