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

(cherry picked from commit 75bedbe2ed)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2020-05-22 15:22:51 -07:00 committed by GitHub
parent 0714c48719
commit 16d07812dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View 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: