[New-bugs-announce] [issue11248] Tails of generator get lost under zip()

Greg Kochanski report at bugs.python.org
Sat Feb 19 11:50:45 CET 2011

New submission from Greg Kochanski <gpk at kochanski.org>:

When you have a generator as an argument to zip(), code after the last yield statement may not get executed.  The problem is that zip() stops after it gets _one_ exception, i.e. when just one of the generators has finished.

As a result, if there were any important clean-up code at the end of a generator, it will not be executed.   Caches may not get flushed, et cetera.

At the least, this is a documentation bug that needs to be pointed out in both zip() and the definition of a generator().  More realistically, it is a severe wart on the language, because it violates the programmer's reasonable expectation that a generator executes until it falls off the end of the function.  It means that a generator becomes conceptually nasty: you cannot predict what it will do based just on an inspection of the code and the code it calls.

Likely, the same behavior happens in itertools, too.

components: None
files: bug312.py
messages: 128842
nosy: gpk-kochanski
priority: normal
severity: normal
status: open
title: Tails of generator get lost under zip()
type: behavior
versions: Python 2.6
Added file: http://bugs.python.org/file20794/bug312.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list