diff options
author | Gregory P. Smith <gps@google.com> | 2020-03-05 00:45:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-05 00:45:22 (GMT) |
commit | 85cf1d514b84dc9a4bcb40e20a12e1d82ff19f20 (patch) | |
tree | 4d97683755d61456848d3cd1e94c218c46110f74 /Lib/inspect.py | |
parent | d4a09c13ddd91a9bc1b4ba76ff4e8a153334a1e2 (diff) | |
download | cpython-85cf1d514b84dc9a4bcb40e20a12e1d82ff19f20.zip cpython-85cf1d514b84dc9a4bcb40e20a12e1d82ff19f20.tar.gz cpython-85cf1d514b84dc9a4bcb40e20a12e1d82ff19f20.tar.bz2 |
bpo-13487: Use sys.modules.copy() in inspect.getmodule() for thread safety. (GH-18786)
`list(sys.modules.items())` was apparently not immune to "dictionary
changed size during iteration" errors.
Tested internally using an integration test that has run into this a couple of times in the past two years. With this patch applied, the test is no longer flaky.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index bb82f96..125bd45 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -741,7 +741,7 @@ def getmodule(object, _filename=None): return sys.modules.get(modulesbyfile[file]) # Update the filename to module name cache and check yet again # Copy sys.modules in order to cope with changes while iterating - for modname, module in list(sys.modules.items()): + for modname, module in sys.modules.copy().items(): if ismodule(module) and hasattr(module, '__file__'): f = module.__file__ if f == _filesbymodname.get(modname, None): |