Changeset 1566
- Timestamp:
- 12/28/06 13:03:35
- Files:
-
- branches/cherrypy-2.x/cherrypy/lib/autoreload.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/cherrypy-2.x/cherrypy/lib/autoreload.py
r1315 r1566 2 2 # stolen a lot from Ian Bicking's WSGIKit (www.wsgikit.org) 3 3 4 import errno 4 5 import os 6 import re 5 7 import sys 6 8 import time … … 10 12 reloadFiles = [] 11 13 ignoreFiles = ['<string>'] 14 match = ".*" 15 12 16 13 17 def reloader_thread(freq): 14 18 mtimes = {} 15 19 16 def fileattr(m):17 if hasattr(m, "__loader__"):18 if hasattr(m.__loader__, "archive"):19 return m.__loader__.archive20 return getattr(m, "__file__", None)21 22 20 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: 24 31 if filename and filename not in ignoreFiles: 32 33 orig = filename 25 34 if filename.endswith(".pyc"): 26 35 filename = filename[:-1] 36 37 # Get the last-modified time of the source file. 27 38 try: 28 39 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 30 48 sys.exit(3) # force reload 49 31 50 if filename not in mtimes: 32 51 mtimes[filename] = mtime 33 52 continue 53 34 54 if mtime > mtimes[filename]: 35 55 sys.exit(3) # force reload

