Skip to content

Commit 4b99d39

Browse files
committed
gh-120170: Exclude __mp_main__ in C version of whichmodule()
Importing multiprocessing adds an alias to __main__ named __mp_main__. In #23403, the Python version of whichmodule() was fixed to exclude __mp_main__. Apply the same fix to the C version of the function.
1 parent 417bec7 commit 4b99d39

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix an issue in the :mod:`!_pickle` extension module in which importing
2+
:mod:`multiprocessing` could change how pickle identifies which module an
3+
object belongs to, potentially breaking the unpickling of those objects.

Modules/_pickle.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,10 @@ _checkmodule(PyObject *module_name, PyObject *module,
18881888
_PyUnicode_EqualToASCIIString(module_name, "__main__")) {
18891889
return -1;
18901890
}
1891+
if (PyUnicode_Check(module_name) &&
1892+
_PyUnicode_EqualToASCIIString(module_name, "__mp_main__")) {
1893+
return -1;
1894+
}
18911895

18921896
PyObject *candidate = get_deep_attribute(module, dotted_path, NULL);
18931897
if (candidate == NULL) {

0 commit comments

Comments
 (0)