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()

-- 
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.

Reply via email to