8000 gh-112087: Make `list.extend(dict)` behave atomically by colesbury · Pull Request #117438 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-112087: Make list.extend(dict) behave atomically #117438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-112087: Make list.extend(dict) behave atomically
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.
  • Loading branch information
colesbury committed Apr 1, 2024
commit a1fa3fbb33adc103360b94b228fc3d4cc271e57b
5 changes: 5 additions & 0 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,11 @@ _list_extend(PyListObject *self, PyObject *iterable)
res = list_extend_set(self, (PySetObject *)iterable);
Py_END_CRITICAL_SECTION2();
}
else if (PyDict_CheckExact(iterable)) {
Py_BEGIN_CRITICAL_SECTION2(self, iterable);
res = list_extend_dict(self, (PyDictObject *)iterable, 0 /*keys*/);
Py_END_CRITICAL_SECTION2();
}
else if (Py_IS_TYPE(iterable, &PyDictKeys_Type)) {
PyDictObject *dict = ((_PyDictViewObject *)iterable)->dv_dict;
Py_BEGIN_CRITICAL_SECTION2(self, dict);
Expand Down
0