diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/pickle.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index 3fc2596..663773f 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -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: |