bpo-13487: Use sys.modules.copy() in inspect.getmodule() for thread s… · python/cpython@7058d2d (original) (raw)

Original file line number Diff line number Diff line change
@@ -729,7 +729,7 @@ def getmodule(object, _filename=None):
729 729 return sys.modules.get(modulesbyfile[file])
730 730 # Update the filename to module name cache and check yet again
731 731 # Copy sys.modules in order to cope with changes while iterating
732 -for modname, module in list(sys.modules.items()):
732 +for modname, module in sys.modules.copy().items():
733 733 if ismodule(module) and hasattr(module, '__file__'):
734 734 f = module.__file__
735 735 if f == _filesbymodname.get(modname, None):