Mailing List Archive

bpo-42406: Fix whichmodule() with multiprocessing (GH-23403)
https://github.com/python/cpython/commit/86684319d3dad8e1a7b0559727a48e0bc50afb01
commit: 86684319d3dad8e1a7b0559727a48e0bc50afb01
branch: master
author: Renato Cunha <renatocunha@acm.org>
committer: gpshead <greg@krypto.org>
date: 2020-11-29T10:23:15-08:00
summary:

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>

files:
A Misc/NEWS.d/next/Library/2020-11-19-10-44-41.bpo-42406.r9rNCj.rst
M Lib/pickle.py

diff --git a/Lib/pickle.py b/Lib/pickle.py
index cbac5f168b45e..e63a8b6e4dbb7 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 0000000000000..c157df138a5ea
--- /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.

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins
bpo-42406: Fix whichmodule() with multiprocessing (GH-23403) [ In reply to ]
https://github.com/python/cpython/commit/b1c48e513624641d6472262c33d09624170ea1f5
commit: b1c48e513624641d6472262c33d09624170ea1f5
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
committer: miss-islington <31488909+miss-islington@users.noreply.github.com>
date: 2020-11-29T10:43:36-08:00
summary:

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 86684319d3dad8e1a7b0559727a48e0bc50afb01)

Co-authored-by: Renato Cunha <renatocunha@acm.org>

files:
A Misc/NEWS.d/next/Library/2020-11-19-10-44-41.bpo-42406.r9rNCj.rst
M Lib/pickle.py

diff --git a/Lib/pickle.py b/Lib/pickle.py
index af50a9b0c06bb..05f30b6b168b5 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 0000000000000..c157df138a5ea
--- /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.

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins
bpo-42406: Fix whichmodule() with multiprocessing (GH-23403) [ In reply to ]
https://github.com/python/cpython/commit/fcf7391f598e027a083173662a3ecf7865251291
commit: fcf7391f598e027a083173662a3ecf7865251291
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
committer: miss-islington <31488909+miss-islington@users.noreply.github.com>
date: 2020-11-29T10:47:31-08:00
summary:

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 86684319d3dad8e1a7b0559727a48e0bc50afb01)

Co-authored-by: Renato Cunha <renatocunha@acm.org>

files:
A Misc/NEWS.d/next/Library/2020-11-19-10-44-41.bpo-42406.r9rNCj.rst
M Lib/pickle.py

diff --git a/Lib/pickle.py b/Lib/pickle.py
index cbac5f168b45e..e63a8b6e4dbb7 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 0000000000000..c157df138a5ea
--- /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.

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins