Is defaultdict thread safe?

Stefan Behnel stefan_ml at behnel.de
Mon Jan 25 05:55:19 EST 2010


Frank Millman, 25.01.2010 09:59:
> Is defaultdict thread safe?
> 
> Assume I have -
> 
>     from collections import defaultdict
>     my_dict = defaultdict(list)
> 
> If two threads call "my_dict['abc'].append(...)" simultaneously, is it 
> guaranteed that my_dict['abc'] will end up containing two elements?

Thread-safety is implementation specific. Other runtime environments than
CPython (e.g. Jython, IronPython, PyPy) may or may not provide any
guarantees on thread safety here.

Stefan



More information about the Python-list mailing list