Issue #21905: Avoid RuntimeError in pickle.whichmodule() when sys.modules is mutated while iterating.

Patch by Olivier Grisel.
This commit is contained in:
Antoine Pitrou 2014-10-04 22:15:27 +02:00
parent fb8eaae6eb
commit e1618491ad
3 changed files with 7 additions and 1 deletions

View File

@ -280,7 +280,9 @@ def whichmodule(obj, name, allow_qualname=False):
module_name = getattr(obj, '__module__', None)
if module_name is not None:
return module_name
for module_name, module in sys.modules.items():
# 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 list(sys.modules.items()):
if module_name == '__main__' or module is None:
continue
try:

View File

@ -494,6 +494,7 @@ Eddy De Greef
Grant Griffin
Andrea Griffini
Duncan Grisby
Olivier Grisel
Fabian Groffen
Eric Groo
Dag Gruneau

View File

@ -22,6 +22,9 @@ Core and Builtins
Library
-------
- Issue #21905: Avoid RuntimeError in pickle.whichmodule() when sys.modules
is mutated while iterating. Patch by Olivier Grisel.
- Issue #22219: The zipfile module CLI now adds entries for directories
(including empty directories) in ZIP file.