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>
(cherry picked from commit 86684319d3)

Co-authored-by: Renato Cunha <renatocunha@acm.org>
This commit is contained in:
Miss Islington (bot) 2020-11-29 10:47:31 -08:00 committed by GitHub
parent cf47b3969e
commit fcf7391f59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View 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:

View File

@ -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.