Comment

Don Heidrich

Yes, this makes perfect sense. If i recreate pump4 later by say running the example again, I do see the exception from the previous generator as it is destroyed. This is consistent with your comment. I think it's interesting to note that the the exception is triggered not by the loop break per se, but by subsequent reference destruction by another action such as garbage collection or reassignment of the var. Thank you Yao! I learned something important.

Replies

Angel Salazar

If the generator referenced pump4 is running again the result:

for number in pump4:
    print("Got", number)
    if number == 2:
        break
print("All done")

Have sent 2
Got 3
Have sent 3
Got 4
Have sent 4
Last number was sent
All done
>>>

The pump4 generator re-started where it left-off.