-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Closed
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-free-threadingtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
Bug report
Bug description:
Ideally, defaultdict would provide atomic "compute and add only if key is absent" behavior. When __missing__ is called, another thread might insert the key. Or, it can be inserted between the call to the factory function and the PyObject_SetItem() call.
It would help to call PyDict_SetDefaultRef() so that an existing value is not replaced. That still has the issue that the factory function is called when a value already exists for that key but that is arguably a less serious problem. We should not be replacing an existing value.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-142495 fix __missing__ data race condition #142569
- gh-142495: make
defaultdictkeep existed value when racing with__missing__#142668 - [3.14] gh-142495: Make
defaultdictkeep existed value when racing with__missing__(GH-142668) #142832 - [3.13] gh-142495: Make
defaultdictkeep existed value when racing with__missing__(GH-142668) #142858
seberg
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-free-threadingtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump