Some stated that python dictionary is thread safe. Does it mean I can or cannot modify the items in a dictionary while iterating over it?
No. Recent version of python will raise an exception if you try to iterate over a dictionary that has changed size between iterations.
>>> d={'one':1, 'two':2}
>>> for x in d:
... d['three']=3
... print x
...
two
Traceback (most recent call last):
File "", line 1, in
RuntimeError: dictionary changed size during iteration
Notice that you don't need to use threads to see this