[Python-checkins] bpo-40327: Improve atomicity, speed, and memory efficiency of the items() loop (GH-19628)

Raymond Hettinger webhook-mailer at python.org
Tue Apr 21 19:20:56 EDT 2020


https://github.com/python/cpython/commit/75bedbe2ed4119ff18a2ea86c544b3cf08a92e75
commit: 75bedbe2ed4119ff18a2ea86c544b3cf08a92e75
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-04-21T16:20:52-07:00
summary:

bpo-40327: Improve atomicity, speed, and memory efficiency of the items() loop (GH-19628)

files:
M Lib/pickle.py

diff --git a/Lib/pickle.py b/Lib/pickle.py
index d7adc162c98de..1fc8b0d26c6c4 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:



More information about the Python-checkins mailing list