Yield inside try...finally
W Isaac Carroll
icarroll at pobox.com
Thu Jun 5 06:13:43 EDT 2003
More information about the Python-list mailing list
Thu Jun 5 06:13:43 EDT 2003
- Previous message (by thread): Yield inside try...finally
- Next message (by thread): Yield inside try...finally
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Jeremy Fincher wrote:
> I wonder if he's considered relaxing that restriction to allow at most
> *one* try: finally: block, or any number of try: finally: blocks whose
> finally: clauses are identical (which is effectively equivalent to a
> single finally: clause). He could then just compile the finally code
> into an __del__ method on the generator-iterator.
I don't think it's that simple. For example:
def finalgen():
while not done:
try:
foo = makefoo()
yield foo
finally:
cleanup(foo)
yield somethingelse
At the first yield statement, the generator would need a __del__ method
that calls cleanup(foo). At the second yield statement, no __del__
method is needed because cleanup(foo) was called when the generator was
resumed. Solving this problem, however, would lift your proposed
restriction that only one finally block be allowed.
TTFN
- Previous message (by thread): Yield inside try...finally
- Next message (by thread): Yield inside try...finally
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list