Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a race condition in the free-threaded build where concurrent access to
the same lazy-imported submodule attribute could raise :exc:`AttributeError`.
Patch by Bartosz Sławecki.
10 changes: 10 additions & 0 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,16 @@ _Py_module_getattro_impl(PyModuleObject *m, PyObject *name, int suppress)
if (PyErr_Occurred()) {
return NULL;
}
// Other threads could have raced to load the submodule.
// Re-check the module dict to avoid race condition.
attr = _PyObject_GenericGetAttrWithDict((PyObject *)m, name, NULL, 1);
if (attr != NULL) {
return attr;
}
if (PyErr_Occurred()) {
// pass up non-AttributeError exception
return NULL;
}
if (PyDict_GetItemRef(m->md_dict, &_Py_ID(__getattr__), &getattr) < 0) {
return NULL;
}
Expand Down
Loading