Discuss / Python / 进程间通信小节里面的读数据进程

进程间通信小节里面的读数据进程

Topic source
# 读数据进程执行的代码:
def read(q):
    print('Process to read: %s' % os.getpid())
    while True:
        value = q.get(True)  # q.get(True),这一句为什么要传入'True'这个参数值??作用是什么,试过不传参数:value = q.get()也能正常从queue里面取到值
        print('Get %s from queue.' % value)

ostreamBaba

#2 Created at ... [Delete] [Delete and Lock User]

并没有用 可以看一下get的实现

get(self, block=True, timeout=None); 这里的block默认为True 

在从block的意思来看,其实就是阻塞的获取,即当queue里面没有东西的时候,当前进程会被阻塞,直到queue中有东西。


  • 1

Reply