`yield` in a `try/finally` block, pre-Python 2.5

yuce yucetekol at gmail.com
Mon Jun 4 01:49:07 EDT 2007


I had the same problem, you can see: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/130004
for a solution.

Happy hacking,

Yuce

On Jun 4, 8:23 am, Adam Atlas <a... at atlas.st> wrote:
> I'm trying to emulate the Python 2.5 behaviour (PEP 342) of generator
> functions where the `yield` statement is in a `try/finally` block.
> Basically, where the `finally` block is guaranteed to run even if the
> generator doesn't finish running: it simply runs when the generator is
> garbage-collected. Does anyone know a good way of doing this? I'm
> looking to see if there's a way to bring about an exception in another
> frame in pure Python, but I haven't found anything yet.





More information about the Python-list mailing list