Advertisement
Guest User

Untitled

a guest
Sep 21st, 2021
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. queue = []
  2.  
  3. def make_producer():
  4. while True:
  5. print("I don't want these any more")
  6. for i in range(3):
  7. print(f"I'll drop this {i} on the ground")
  8. queue.append(i)
  9. print("Now I will run away")
  10. yield consumer
  11.  
  12. def make_consumer():
  13. while True:
  14. print("I hunger")
  15. while queue:
  16. x = queue.pop()
  17. print(f"Mm, tasty {x}")
  18. print("Nap time")
  19. yield producer
  20.  
  21. producer = make_producer()
  22. consumer = make_consumer()
  23.  
  24. g = producer
  25. count = 0
  26. while True:
  27. g = next(g)
  28. count += 1
  29. if count > 20: break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement