You're very right, new files were not detected. I updated my code accordingly, and also gave a grace time of 200ms before actually reloading.
See https://gist.github.com/4546993 Thanks for the great community support! 2013/1/16 Ævar Arnfjörð Bjarmason <[email protected]> > On Wed, Jan 16, 2013 at 11:26 AM, Jean-Baptiste Quenot <[email protected]> > wrote: > > OK, I didn't know about the "attach-daemon" option. > > Me neither. Looks like something I can use for inotify-hookable too. > > > Here is the python reload script I finally came up with: > > > > #! /usr/bin/python > > > > import pyinotify, sys, os, signal > > > > def callback(evt): > > print "Change detected!", evt > > os.kill(os.getppid(), signal.SIGHUP) > > sys.exit(0) > > > > wm = pyinotify.WatchManager() > > notifier = pyinotify.Notifier(wm, default_proc_fun=callback) > > root = sys.argv[1] > > for parentdir, dirs, files in os.walk(root): > > for file in files: > > if file.endswith(".tmpl") or file.endswith(".py"): > > wm.add_watch(os.path.join(parentdir, file), > > pyinotify.ALL_EVENTS) > > notifier.loop() > > > > And the uwsgi config: > > > > { > > "uwsgi": { > > "attach-daemon": "uwsgi-watch-wc /path/to/my/app", > > "module": "server:application", > > "pythonpath": ["/path/to/my/app"], > > "uid": "www-data", > > "gid": "www-data" > > } > > } > > > > Thanks to all for your useful contributions! > > I've only read the code for this and not actually tried it, but > there's a few major caveats with it that my inotify-hookable deals > with: > > * You're only watching existing files, you need to be adding watches > on directories in case someone adds a file. > > * You're going to restart as soon as you get one inotify event, > that's very wasteful and usually not what you want. > > When someone e.g. does a "git pull" you'll restart right away when > 1/100 files has been changed, and might possibly be back up before > all the files are changed, and before you can re-setup the watch. > > inotify-hookable deals with this by waiting X ms when it gets a > inotify hit waiting for more events, as long as it keeps getting > events it'll extend the wait a bit more before finally running > hooks. > _______________________________________________ > uWSGI mailing list > [email protected] > http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi > -- Jean-Baptiste Quenot
_______________________________________________ uWSGI mailing list [email protected] http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
