[issue23227] Generator's finally block not run if close() called before first iteration

2015-04-23 Thread Stephen Drake
Stephen Drake added the comment: Ok, I can accept that. I think my mistake was to assume that because a generator has a close() method, I could treat it as a lightweight wrapper for another closeable object. But it's better to regard a generator function that wraps an iterable as something

[issue23227] Generator's finally block not run if close() called before first iteration

2015-01-12 Thread Stephen Drake
New submission from Stephen Drake: If a generator has its close() method called before any items are requested from it, a finally block in the generator function will not be executed. I encountered this when wrapping an open file to alter the result of iterating over it. Using a generator