diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index 4fba0fe..1e64243 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -88,7 +88,8 @@ def gen_filenames(only_new=False):
     # application code which might be mutating ``sys.modules``, and this will
     # fail with RuntimeError: cannot mutate dictionary while iterating
     global _cached_modules, _cached_filenames
-    module_values = set(sys.modules.values())
+    module_values = set([module for module in sys.modules.values()
+                         if hasattr(module, '__file__')])
     _cached_filenames = clean_files(_cached_filenames)
     if _cached_modules == module_values:
         # No changes in module list, short-circuit the function
@@ -98,9 +99,7 @@ def gen_filenames(only_new=False):
             return _cached_filenames + clean_files(_error_files)
 
     new_modules = module_values - _cached_modules
-    new_filenames = clean_files(
-        [filename.__file__ for filename in new_modules
-         if hasattr(filename, '__file__')])
+    new_filenames = clean_files([module.__file__ for module in new_modules])
 
     if not _cached_filenames and settings.USE_I18N:
         # Add the names of the .mo files that can be generated
