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

Josiah Carlson jcarlson at uci.edu
Thu Oct 20 04:30:54 CEST 2005


"Phillip J. Eby" <pje at telecommunity.com> wrote:
> For efficiency's sake, however, CPython could simply store the
> execution context dictionary in its "thread state" structure, creating
> an empty dictionary at thread initialization time.  This would make it
> somewhat easier to offer a C API for access to context variables,
> especially where efficiency of access is desirable.  But the proposal
> does not depend on this.

What about a situation in which corutines are handled by multiple
threads?  Any time a corutine passed from one thread to another, it
would lose its state.

While I agree with the obvious "don't do that" response, I don't believe
that the proposal will actually go very far in preventing real problems
when using context managers and generators or corutines.  Why?  How much
task state is going to be monitored/saved?  Just sys?  Perhaps sys and
the module in which a corutine was defined?  Eventually you will have
someone who says, "I need Python to be saving and restoring the state of
the entire interpreter so that I can have a per-user execution
environment that cannot be corrupted by another user."  But how much
farther out is that?

 - Josiah



More information about the Python-Dev mailing list