gen_yield_from_stopped.py 317 B

123456789101112131415161718
  1. # Yielding from stopped generator is ok and results in None
  2. def gen():
  3. return 1
  4. # This yield is just to make this a generator
  5. yield
  6. f = gen()
  7. def run():
  8. print((yield from f))
  9. print((yield from f))
  10. print((yield from f))
  11. try:
  12. next(run())
  13. except StopIteration:
  14. print("StopIteration")