Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1566

Show
Ignore:
Timestamp:
12/28/06 13:03:35
Author:
fumanchu
Message:

2.x backport of [1220] (Fix for #438 (autoreload.py: Server fails to start if a .pyc is imported with no corresponding .py)) and [1337] (New engine.autoreload.match attribute for filtering autoreload to a single package.)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cherrypy-2.x/cherrypy/lib/autoreload.py

    r1315 r1566  
    22# stolen a lot from Ian Bicking's WSGIKit (www.wsgikit.org) 
    33 
     4import errno 
    45import os 
     6import re 
    57import sys 
    68import time 
     
    1012reloadFiles = [] 
    1113ignoreFiles = ['<string>'] 
     14match = ".*" 
     15 
    1216 
    1317def reloader_thread(freq): 
    1418    mtimes = {} 
    1519     
    16     def fileattr(m): 
    17         if hasattr(m, "__loader__"): 
    18             if hasattr(m.__loader__, "archive"): 
    19                 return m.__loader__.archive 
    20         return getattr(m, "__file__", None) 
    21      
    2220    while RUN_RELOADER: 
    23         for filename in map(fileattr, sys.modules.values()) + reloadFiles: 
     21        sysfiles = [] 
     22        for k, m in sys.modules.items(): 
     23            if re.match(match, k): 
     24                if hasattr(m, "__loader__"): 
     25                    if hasattr(m.__loader__, "archive"): 
     26                        k = m.__loader__.archive 
     27                k = getattr(m, "__file__", None) 
     28                sysfiles.append(k) 
     29         
     30        for filename in sysfiles + reloadFiles: 
    2431            if filename and filename not in ignoreFiles: 
     32                 
     33                orig = filename 
    2534                if filename.endswith(".pyc"): 
    2635                    filename = filename[:-1] 
     36                 
     37                # Get the last-modified time of the source file. 
    2738                try: 
    2839                    mtime = os.stat(filename).st_mtime 
    29                 except OSError: 
     40                except OSError, e: 
     41                    if orig.endswith('.pyc') and e[0] == errno.ENOENT: 
     42                        # This prevents us from endlessly restarting if 
     43                        # there is an old .pyc lying around after a .py 
     44                        # file has been deleted. Note that TG's solution 
     45                        # actually deletes the .pyc, but we just ignore it. 
     46                        # See http://www.cherrypy.org/ticket/438. 
     47                        continue 
    3048                    sys.exit(3) # force reload 
     49                 
    3150                if filename not in mtimes: 
    3251                    mtimes[filename] = mtime 
    3352                    continue 
     53                 
    3454                if mtime > mtimes[filename]: 
    3555                    sys.exit(3) # force reload 

Hosted by WebFaction

Log in as guest/cpguest to create tickets