]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Work around an odd error I occasionally see in autoreload (which causes
authorBen Darnell <bdarnell@beaker.local>
Thu, 25 Feb 2010 23:49:08 +0000 (15:49 -0800)
committerBen Darnell <bdarnell@beaker.local>
Thu, 25 Feb 2010 23:49:08 +0000 (15:49 -0800)
autoreload to loop endlessly without restarting the process)

tornado/autoreload.py

index 4b3ab364c520895612045fd49067ef6a84fb275a..8fd5f88d44eec99d13c66da1d8d79fce35a4595a 100644 (file)
@@ -27,6 +27,7 @@ import logging
 import os
 import os.path
 import sys
+import types
 
 
 def start(io_loop=None, check_time=500):
@@ -50,6 +51,11 @@ def _reload_on_update(io_loop, modify_times):
         # We already tried to reload and it didn't work, so don't try again.
         return
     for module in sys.modules.values():
+        # Some modules play games with sys.modules (e.g. email/__init__.py
+        # in the standard library), and occasionally this can cause strange
+        # failures in getattr.  Just ignore anything that's not an ordinary
+        # module.
+        if not isinstance(module, types.ModuleType): continue
         path = getattr(module, "__file__", None)
         if not path: continue
         if path.endswith(".pyc") or path.endswith(".pyo"):