bpo-13487: Use sys.modules.copy() in inspect.getmodule() for thread s… · python/cpython@85cf1d5

Original file line numberDiff line numberDiff line change

@@ -741,7 +741,7 @@ def getmodule(object, _filename=None):

741741

return sys.modules.get(modulesbyfile[file])

742742

# Update the filename to module name cache and check yet again

743743

# Copy sys.modules in order to cope with changes while iterating

744-

for modname, module in list(sys.modules.items()):

744+

for modname, module in sys.modules.copy().items():

745745

if ismodule(module) and hasattr(module, '__file__'):

746746

f = module.__file__

747747

if f == _filesbymodname.get(modname, None):