diff -r 919259054621 Lib/inspect.py --- a/Lib/inspect.py Sun Nov 27 00:19:53 2011 +0100 +++ b/Lib/inspect.py Sat Nov 26 18:49:16 2011 -0800 @@ -482,7 +482,7 @@ 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 sys.modules.items(): + for modname, module in list(sys.modules.items()): if ismodule(module) and hasattr(module, '__file__'): f = module.__file__ if f == _filesbymodname.get(modname, None):