Thread-safe way to add a key to a dict only if it isn't already there?

Ian Kelly ian.g.kelly at gmail.com
Fri Jul 6 13:57:57 EDT 2018


On Fri, Jul 6, 2018 at 11:56 AM INADA Naoki <songofacandy at gmail.com> wrote:
>
> D.setdefault('c', None)

Not guaranteed to be atomic.

I think the only safe way to do it is with a Lock.


More information about the Python-list mailing list