[Python-Dev] Revised Proposal: thread.get_dict

Jim Fulton jim at zope.com
Wed Jun 30 12:24:13 EDT 2004

Tim Peters wrote:
> [Jim Fulton]
>>We often want to associate data with threads.  Python
>>manages a dictionary per-tread for this purpose, but there's
>>currently no way to get to this dictionary from Python.
>>I propose, for 2.4, to add a "local" class to the thread
>>module for creating thread-local objects,
> It's probably better to add this to the (coded in Python) threading
> module, and include the Python implementation there.  The threading
> module can replace the Python implementation with something from the
> (coded in C) thread module if possible.  This is so implementations
> other than CPython get something usable right away (only CPython has
> the C API, of course).

So the C implementation would be in the thread module, perhaps
under a funny name, but the official place to import it from is the
threading module?

> ... the doctest ...
>>  >>> thread
> That was meant to be "import thread", right?

Oops, yup.  My *real* prototype has "import zope.thread". :)

> BTW, I suggest it would be better if the string key had a
> unique-to-this-purpose prefix, e.g. 'threading.local.' +
> str(id(self)).  I'm uncomfortable with reserving all "string keys that
> look like integers" implicitly for this use.



Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org

More information about the Python-Dev mailing list