[ python-Bugs-1542308 ] Nested finally in generators don't follow PEP 342

SourceForge.net noreply at sourceforge.net
Tue Aug 22 23:00:25 CEST 2006


Bugs item #1542308, was opened at 2006-08-17 18:56
Message generated for change (Comment added) made by etrepum
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1542308&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.5
Status: Open
Resolution: None
Priority: 8
Submitted By: Bob Ippolito (etrepum)
Assigned to: Nobody/Anonymous (nobody)
Summary: Nested finally in generators don't follow PEP 342

Initial Comment:
The close() and GC interaction of generators that use yield inside of finally 
blocks doesn't execute correctly when nested. See the attached example.

More information about the issue is in the Mozilla bug tracker (they found 
a similar bug in their implementation for JS 1.7):
https://bugzilla.mozilla.org/show_bug.cgi?id=349012

----------------------------------------------------------------------

>Comment By: Bob Ippolito (etrepum)
Date: 2006-08-22 17:00

Message:
Logged In: YES 
user_id=139309

Uh no, that wouldn't reach an infinite loop because any attempt to yield during 
close will raise RuntimeError and terminate the loop.

The problem is that finally doesn't execute. Finally clauses always must execute. 
If they don't, then they're worthless.

The real strange issue is that if close is called, then GC makes a second attempt, 
and it *does* execute the outer finally clause. There are definitely bugs here.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2006-08-22 16:47

Message:
Logged In: YES 
user_id=6380

I lost my patience halfway through reading the Mozilla bug
tracker, but IMO this works as designed.  The philosophical
question is, would you rather see the outer finally clause
reached in your example, or would you rather see the
following generator terminated upon close? (If you "fix" the
former, the latter ends up in an infinite loop when you
attempt to close() or GC it.)

def gen():
  while True:
    try:
      yield
    except:
      pass

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1542308&group_id=5470


More information about the Python-bugs-list mailing list