E
Emanuele D'Arrigo
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
safe?
Thanks for your help!
Manu
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
safe?
Thanks for your help!
Manu