[Python-Dev] problem with recursive "yield from" delegation
ncoghlan at gmail.com
Thu Mar 8 01:47:00 CET 2012
On Thu, Mar 8, 2012 at 10:32 AM, Jim J. Jewett <jimjjewett at gmail.com> wrote:
> How is this a problem?
> Re-entering a generator is a bug. Python caught it and raised an
> appropriate exception.
No, the problem was that the interpreter screwed up the state of the
generators while attempting to deal with the erroneous reentry. The
ValueError *should* just be caught and completely suppressed by the
try/except block, but that wasn't quite happening properly - the
failed attempt at reentry left the generators in a dodgy state (which
is why the subsequent "3" was being produced, but then the expected
final "4" vanished into the electronic ether).
Benjamin figured out where the generator's reentrancy check was going
wrong, so Stefan's example should do the right thing in the next alpha
(i.e. the ValueError will still get raised and suppressed by the
try/except block, the inner generator will complete, but the outer
generator will also continue on to produce the final value).
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev