diff options
author | Renato Cunha <renatocunha@acm.org> | 2020-11-29 18:23:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-29 18:23:15 (GMT) |
commit | 86684319d3dad8e1a7b0559727a48e0bc50afb01 (patch) | |
tree | 77a9a88f15de446bd88c59d06f9380f2be210c7b | |
parent | 86150d39c888579b65841f4391d054b7b3eff9f2 (diff) | |
download | cpython-86684319d3dad8e1a7b0559727a48e0bc50afb01.zip cpython-86684319d3dad8e1a7b0559727a48e0bc50afb01.tar.gz cpython-86684319d3dad8e1a7b0559727a48e0bc50afb01.tar.bz2 |
bpo-42406: Fix whichmodule() with multiprocessing (GH-23403)
* 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>
-rw-r--r-- | Lib/pickle.py | 4 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2020-11-19-10-44-41.bpo-42406.r9rNCj.rst | 3 |
2 files changed, 6 insertions, 1 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index cbac5f1..e63a8b6 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -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 index 0000000..c157df1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-11-19-10-44-41.bpo-42406.r9rNCj.rst @@ -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. |