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

Changeset 661

Show
Ignore:
Timestamp:
09/18/05 22:15:31
Author:
fumanchu
Message:

Moved a KeyboardInterrupt? trap to remove autoreload's dependency on cherrypy.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/lib/autoreload.py

    r551 r661  
    66import time 
    77import thread 
    8 import cherrypy 
    98 
    109RUN_RELOADER = True 
     
    1312def reloader_thread(): 
    1413    mtimes = {} 
     14     
     15    def fileattr(m): 
     16        return getattr(m, "__file__", None) 
     17     
    1518    while RUN_RELOADER: 
    16         for filename in filter(lambda v: v, map(lambda m: getattr(m, "__file__", None), sys.modules.values())) + reloadFiles: 
    17             if filename.endswith(".pyc"): 
    18                 filename = filename[:-1] 
    19             try: 
    20                 mtime = os.stat(filename).st_mtime 
    21             except OSError: 
    22                 sys.exit(3) # force reload 
    23             if filename not in mtimes: 
    24                 mtimes[filename] = mtime 
    25                 continue 
    26             if mtime > mtimes[filename]: 
    27                 sys.exit(3) # force reload 
     19        for filename in map(fileattr, sys.modules.values()) + reloadFiles: 
     20            if filename: 
     21                if filename.endswith(".pyc"): 
     22                    filename = filename[:-1] 
     23                try: 
     24                    mtime = os.stat(filename).st_mtime 
     25                except OSError: 
     26                    sys.exit(3) # force reload 
     27                if filename not in mtimes: 
     28                    mtimes[filename] = mtime 
     29                    continue 
     30                if mtime > mtimes[filename]: 
     31                    sys.exit(3) # force reload 
    2832        time.sleep(1) 
    2933 
     
    5458            pass 
    5559    else: 
    56         try: 
    57             sys.exit(restart_with_reloader()) 
    58         except KeyboardInterrupt: 
    59             cherrypy.log("<Ctrl-C> hit: shutting down autoreloader", "HTTP") 
     60        # If KeyboardInterrupt is raised within restart_with_reloader, 
     61        # let it propagate out to the caller. 
     62        sys.exit(restart_with_reloader()) 
  • trunk/cherrypy/server.py

    r616 r661  
    5656        # when autoreload calls sys.exit. 
    5757        if not initOnly: 
    58             autoreload.main(_start, (initOnly, serverClass)) 
     58            try: 
     59                autoreload.main(_start, (initOnly, serverClass)) 
     60            except KeyboardInterrupt: 
     61                cherrypy.log("<Ctrl-C> hit: shutting down autoreloader", "HTTP") 
    5962            return 
    6063     

Hosted by WebFaction

Log in as guest/cpguest to create tickets