Fine by me, although I doubt it works in windows due to their (lack of) signal handling.
On Feb 12, 2:40 am, Anand Chitipothu <[email protected]> wrote: > 2011/2/11 Justin Davis <[email protected]>: > > > > > > > > > > > Hey everyone, > > > I modified the webpy reloader to be less kind in general -- syntax > > errors, for instance, will just kill the process -- but it generally > > gets rid of issues with reloader not picking up changes. It only works > > in linux, by waking up every second to check for changes. If anyone's > > interested, here's the code and how to use it: > > > app = web.application(urls, globals() # as usual > > > ## Reloader > > import sys, os, signal, pprint, types > > class PeriodicReloader(object): > > def __init__(self, interval=1): > > self.interval = interval > > self.mtimes = {} > > self.sig_setup() > > > def sig_setup(self): > > signal.signal(signal.SIGALRM, self.check) > > signal.alarm(self.interval) > > > def check(self, signum, frame): > > for mod in sys.modules.values(): > > if not isinstance(mod, types.ModuleType): > > continue > > > path = getattr(mod, '__file__', None) > > if not path: > > continue > > > mtime = os.stat(mod.__file__).st_mtime > > if mod.__file__.endswith('.pyc') and > > os.path.exists(mod.__file__[:-1]): > > mtime = max(os.stat(mod.__file__[:-1]).st_mtime, > > mtime) > > > if mod not in self.mtimes: > > self.mtimes[mod] = mtime > > elif self.mtimes[mod] < mtime: > > web.debug("Reloading app due to module change") > > os.execv(sys.executable, [sys.executable] + sys.argv) > > self.sig_setup() > > > ### Go ### > > if __name__ == '__main__': > > if web.config.debug: > > PeriodicReloader() > > app.run() > > Very nice! > > I see a small problem with this approach. It is possible that the > reloader can get activated while the app is serving a request. Anyway, > it is not that big problem in development. > > I'm tempted to include this in web.py. Justin, are you fine with > including this in web.py with publicdomain license? > > Any objections? > > Anand -- You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/webpy?hl=en.
