thread-local data

Emanuele D'Arrigo manu3d at
Fri Feb 6 11:11:55 EST 2009

Hi everybody,

Assuming a snippet such as:

threadLocalData = threading.local()
threadLocalData.myDictionary = self.myDictionary

is it correct to say that threadLocalData.myDictionary is NOT a thread-
local -copy- of self.myDictionary but it's actually pointing to the
same object?

If that's the case, and assuming I want to iterate over the dictionary
without it changing under my nose while I'm in the loop, would it be
better to encase the whole loop in lock-protected section or  would it
be better to make a copy of the dictionary first and then iterate over
that one? Given that in this particular thread I do not want to modify
the dictionary, conceptually a copy would work. But would making
thread-local copy be just as slow as making the whole loop thread

Thanks for your help!


More information about the Python-list mailing list