[Python-Dev] Pre-PEP: Task-local variables

Phillip J. Eby pje at telecommunity.com
Thu Oct 20 19:14:08 CEST 2005

At 10:40 PM 10/20/2005 +1000, Nick Coghlan wrote:
>Phillip J. Eby wrote:
> > This is still rather rough, but I figured it's easier to let everybody 
> fill
> > in the remaining gaps by arguments than it is for me to pick a position I
> > like and try to convince everybody else that it's right.  :)  Your 
> feedback
> > is requested and welcome.
>I think you're actually highlighting a bigger issue with the behaviour of
>"yield" inside a "with" block, and working around it rather than fixing the
>fundamental problem.
>The issue with "yield" causing changes to leak to outer scopes isn't limited
>to coroutine style usage - it can happen with generator-iterators, too.
>What's missing is a general way of saying "suspend this context temporarily,
>and resume it when done".

Actually, it's fairly simple to write a generator decorator using 
context.swap() that saves and restores the current execution state around 
next()/send()/throw() calls, if you prefer it to be the generator's 
responsibility to maintain such context.

More information about the Python-Dev mailing list