Skip to content

Commit 363da51

Browse files
colesburydiegorusso
authored andcommitted
pythongh-112087: Make list.extend(dict) behave atomically (python#117438)
Add a special case for `list.extend(dict)` and `list(dict)` so that those patterns behave atomically with respect to modifications to the list or dictionary. This is required by multiprocessing, which assumes that `list(_finalizer_registry)` is atomic.
1 parent eb8117e commit 363da51

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Objects/listobject.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,11 @@ _list_extend(PyListObject *self, PyObject *iterable)
13741374
res = list_extend_set(self, (PySetObject *)iterable);
13751375
Py_END_CRITICAL_SECTION2();
13761376
}
1377+
else if (PyDict_CheckExact(iterable)) {
1378+
Py_BEGIN_CRITICAL_SECTION2(self, iterable);
1379+
res = list_extend_dict(self, (PyDictObject *)iterable, 0 /*keys*/);
1380+
Py_END_CRITICAL_SECTION2();
1381+
}
13771382
else if (Py_IS_TYPE(iterable, &PyDictKeys_Type)) {
13781383
PyDictObject *dict = ((_PyDictViewObject *)iterable)->dv_dict;
13791384
Py_BEGIN_CRITICAL_SECTION2(self, dict);

0 commit comments

Comments
 (0)