https://github.com/python/cpython/commit/05a19b5e56894fd1e63aff6b38fb23ad7c7b3047
commit: 05a19b5e56894fd1e63aff6b38fb23ad7c7b3047
branch: main
author: Daniel Li <daniel...@deshaw.com>
committer: hugovk <1324225+hug...@users.noreply.github.com>
date: 2025-05-23T21:45:45+03:00
summary:

gh-120170: Exclude __mp_main__ in C version of whichmodule() (#120171)

Co-authored-by: Lysandros Nikolaou <lisandros...@gmail.com>

files:
A Misc/NEWS.d/next/Library/2024-06-06-17-49-07.gh-issue-120170.DUxhmT.rst
M Modules/_pickle.c

diff --git 
a/Misc/NEWS.d/next/Library/2024-06-06-17-49-07.gh-issue-120170.DUxhmT.rst 
b/Misc/NEWS.d/next/Library/2024-06-06-17-49-07.gh-issue-120170.DUxhmT.rst
new file mode 100644
index 00000000000000..ce7d874aa20375
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-06-06-17-49-07.gh-issue-120170.DUxhmT.rst
@@ -0,0 +1,3 @@
+Fix an issue in the :mod:`!_pickle` extension module in which importing
+:mod:`multiprocessing` could change how pickle identifies which module an
+object belongs to, potentially breaking the unpickling of those objects.
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index d260f1a68f8c70..29ef0cb0c2e088 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -1879,6 +1879,10 @@ _checkmodule(PyObject *module_name, PyObject *module,
             _PyUnicode_EqualToASCIIString(module_name, "__main__")) {
         return -1;
     }
+    if (PyUnicode_Check(module_name) &&
+            _PyUnicode_EqualToASCIIString(module_name, "__mp_main__")) {
+        return -1;
+    }
 
     PyObject *candidate = getattribute(module, dotted_path, 0);
     if (candidate == NULL) {

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to