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

Original file line number Diff line number Diff line change
@@ -741,7 +741,7 @@ def getmodule(object, _filename=None):
741 741 return sys.modules.get(modulesbyfile[file])
742 742 # Update the filename to module name cache and check yet again
743 743 # 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():
745 745 if ismodule(module) and hasattr(module, '__file__'):
746 746 f = module.__file__
747 747 if f == _filesbymodname.get(modname, None):