Here is a slight modification of Kota's patch, plus a unit test.
The modification was only to change "except GeneratorExit:" to "finally:" so that GeneratorExit propagates to any generators enclosing SegmentedIterable. I don't know of any right now, but future middlewares could easily introduce them.
Now that we have a unit test, I believe this patch to be ready for review.
Here is a slight modification of Kota's patch, plus a unit test.
The modification was only to change "except GeneratorExit:" to "finally:" so that GeneratorExit propagates to any generators enclosing SegmentedIterable. I don't know of any right now, but future middlewares could easily introduce them.
Now that we have a unit test, I believe this patch to be ready for review.