From 05a19b5e56894fd1e63aff6b38fb23ad7c7b3047 Mon Sep 17 00:00:00 2001 From: Daniel Li Date: Fri, 23 May 2025 14:45:45 -0400 Subject: [PATCH] gh-120170: Exclude __mp_main__ in C version of whichmodule() (#120171) Co-authored-by: Lysandros Nikolaou --- .../Library/2024-06-06-17-49-07.gh-issue-120170.DUxhmT.rst | 3 +++ Modules/_pickle.c | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2024-06-06-17-49-07.gh-issue-120170.DUxhmT.rst 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 000000000000..ce7d874aa203 --- /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 d260f1a68f8c..29ef0cb0c2e0 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) { -- 2.47.3