]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40327: Improve atomicity, speed, and memory efficiency of the items() loop (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 22 May 2020 22:22:51 +0000 (15:22 -0700)
committerGitHub <noreply@github.com>
Fri, 22 May 2020 22:22:51 +0000 (15:22 -0700)
(cherry picked from commit 75bedbe2ed4119ff18a2ea86c544b3cf08a92e75)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Lib/pickle.py

index 515cb8a0bb3f1a28f15cdfd428996eee943a3dcf..af50a9b0c06bb017c5fad4b17e7f9c169e0779c9 100644 (file)
@@ -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: