Commits

Robert Brewer committed 8af1b30

New engine.autoreload_match attribute for filtering autoreload to a single package (adapted from TG).

Comments (0)

Files changed (1)

cherrypy/_cpengine.py

 
 import cgi
 import os
+import re
 import signal
 import sys
 import threading
 STARTING = None
 STARTED = 1
 
-
-def fileattr(m):
-    if hasattr(m, "__loader__"):
-        if hasattr(m.__loader__, "archive"):
-            return m.__loader__.archive
-    return getattr(m, "__file__", None)
-
-
 try:
     if hasattr(signal, "SIGHUP"):
         def SIGHUP(signum=None, frame=None):
     deadlock_poll_freq = 60
     autoreload_on = True
     autoreload_frequency = 1
+    autoreload_match = ".*"
     
     def __init__(self):
         self.state = STOPPED
     
     def autoreload(self):
         """Reload the process if registered files have been modified."""
-        for filename in map(fileattr, sys.modules.values()) + self.reload_files:
+        sysfiles = []
+        for k, m in sys.modules.items():
+            if re.match(self.autoreload_match, k):
+                if hasattr(m, "__loader__"):
+                    if hasattr(m.__loader__, "archive"):
+                        k = m.__loader__.archive
+                k = getattr(m, "__file__", None)
+                sysfiles.append(k)
+        
+        for filename in sysfiles + self.reload_files:
             if filename:
                 if filename.endswith(".pyc"):
                     filename = filename[:-1]