最近在看python中关于协程的部分,看到廖雪峰的官方网站中关于消费者和生产者那一部分有些困惑,于是自己研究了一下,有了以下了解:
代码:
def consumer():
r = 'a'
while True:
print('there')
n = yield r
print('here')
if not n:
return
print('[CONSUMER] Consuming %s...' % n)
r = '200 OK'
def produce(c):
c.send(None)
n = 0