[Python-Dev] Free threading

Guido van Rossum guido@python.org
Wed, 08 Aug 2001 18:30:54 -0400


> We need thread-local storage, anyway.  When I'm a little farther into my
> work on Decimal, I'm going to take a hard look at this because context
> needs to be global on a per-thread basis...

(Thick French accent:) "We already got one!"

In the C API, use PyThreadState_GetDict(): it returns a per-thread
dictionary.  The convention is that you pick a key unique to your
extension module (e.g. your full extension module name) and then store
your per-thread data under this key.

In Python, you can store instance variables on the current thread
object -- use threading.currentThread() to access it.

--Guido van Rossum (home page: http://www.python.org/~guido/)