From 2f60a152e43fbb0cfc53e516e6ce41dd184b4005 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 20 Apr 2020 13:24:45 -0700 Subject: [PATCH] bpo-40327: Improve atomicity, speed, and memory efficiency of the items() loop --- Lib/pickle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pickle.py b/Lib/pickle.py index d7adc162c98de9..1fc8b0d26c6c47 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -339,7 +339,7 @@ def whichmodule(obj, name): return module_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 list(sys.modules.items()): + for module_name, module in sys.modules.copy().items(): if module_name == '__main__' or module is None: continue try: