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.

2 jaren geleden
123456789101112131415161718192021222324
  1. #-*- coding:utf8 -*-
  2. def consumer():
  3. r = ''
  4. while True:
  5. n = yield r
  6. if not n:
  7. return
  8. print('[CONSUMER]Consuming %s...' % n)
  9. r = '200 OK'
  10. def producer(c):
  11. # 启动生成器
  12. c.send(None)
  13. n = 0
  14. while n < 5:
  15. n = n + 1
  16. print('[PRODUCER]Producing %s...' % n)
  17. r = c.send(n)
  18. print('[PRODUCER]Consumer return: %s' % r)
  19. c.close()
  20. if __name__ == '__main__':
  21. c = consumer()
  22. producer(c)