为什么读者进程没有开始?

时间:2018-05-17 15:15:40

标签: python process

我正在学习使用Queue在两个进程之间进行通信。以下是摘录:

import os
import time
import random
from multiprocessing import Process,Queue

def write(q):
    print("Begin to write data into queue in process:",os.getpid())
    for char in ['A','B','C']:
        print("Put %s to queue" %char)
        q.put(char)
        time.sleep(random.random())


def read(q):
    print("Begin to read data into queue in process: {}".format(os.getpid()))
    while True:
        value = q.get(True)
        print("Get {0} from queue".format(value))


if __name__ == '__main__':
    q=Queue()
    #写队列进程
    process_writer=Process(target=write,args=(q,))
    #读队列进程
    process_reader=Process(target=read,args=(q,))
    process_writer.start()
    process_reader.start()
    #process_writer.join()  
    process_reader.terminate()

嗨,为什么process_reader开始加班我对process_writer.join()行进行评论?

0 个答案:

没有答案