]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42406: Fix whichmodule() with multiprocessing (GH-23403)
authorRenato Cunha <renatocunha@acm.org>
Sun, 29 Nov 2020 18:23:15 +0000 (15:23 -0300)
committerGitHub <noreply@github.com>
Sun, 29 Nov 2020 18:23:15 +0000 (10:23 -0800)
* bpo-42406: Fix whichmodule() with multiprocessing

Signed-off-by: Renato L. de F. Cunha <renatoc@br.ibm.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Lib/pickle.py
Misc/NEWS.d/next/Library/2020-11-19-10-44-41.bpo-42406.r9rNCj.rst [new file with mode: 0644]

index cbac5f168b45eb8c87245d6f1318192b3bcb47f9..e63a8b6e4dbb7006cc1383f43b26e61b3c90db79 100644 (file)
@@ -340,7 +340,9 @@ def whichmodule(obj, name):
     # Protect the iteration by using a list copy of sys.modules against dynamic
     # modules that trigger imports of other modules upon calls to getattr.
     for module_name, module in sys.modules.copy().items():
-        if module_name == '__main__' or module is None:
+        if (module_name == '__main__'
+            or module_name == '__mp_main__'  # bpo-42406
+            or module is None):
             continue
         try:
             if _getattribute(module, name)[0] is obj:
diff --git a/Misc/NEWS.d/next/Library/2020-11-19-10-44-41.bpo-42406.r9rNCj.rst b/Misc/NEWS.d/next/Library/2020-11-19-10-44-41.bpo-42406.r9rNCj.rst
new file mode 100644 (file)
index 0000000..c157df1
--- /dev/null
@@ -0,0 +1,3 @@
+We fixed an issue in `pickle.whichmodule` in which importing
+`multiprocessing` could change the how pickle identifies which module an
+object belongs to, potentially breaking the unpickling of those objects.