You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- #-*- coding:utf8 -*-
- def consumer():
- r = ''
- while True:
- n = yield r
- if not n:
- return
- print('[CONSUMER]Consuming %s...' % n)
- r = '200 OK'
-
- def producer(c):
- # 启动生成器
- c.send(None)
- n = 0
- while n < 5:
- n = n + 1
- print('[PRODUCER]Producing %s...' % n)
- r = c.send(n)
- print('[PRODUCER]Consumer return: %s' % r)
- c.close()
-
- if __name__ == '__main__':
- c = consumer()
- producer(c)
|