At 07:21 PM 01/20/2006 +1000, Nick Coghlan wrote:
>Yeah, it came up in response to PJE's suggestion of task-local variables for
>generators. The basic concept we came up with is that if you're writing a
>generator that uses a specific context, remember to save the original and
>restore it around any calls to yield (at least, I came up with the idea and
>no-one objected to the approach [1]).

That's only because Guido shut down the thread.  :)

For the use cases I had in mind, your approach simply doesn't scale, 
because it requires every yield-point to have global knowledge of all 
"changes to global state" that may have occurred somewhere above it in the 
coroutine call stack.  The only reason I didn't point this out is that 
Guido had asked for a postponement of the discussion.

Since then, I've begun implementing a library that accomodates such use 
cases, as well as a wide variety of other context-management use 
cases.  Source code is at http://svn.eby-sarna.com/Contextual/ and the docs 
are at http://svn.eby-sarna.com/Contextual/context.txt?view=markup

The library uses the current draft of PEP 343 as the basis for 
implementation, and includes a few helper functions that can be used to 
emulate the "with:" statement in Python 2.4 so that it can be used and 
tested.  So far, my impression is that the current 343 spec is at least 
adequate, and maybe even elegant.

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to