Skip to content

Instantly share code, notes, and snippets.

@vinilios
Created January 19, 2010 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinilios/280537 to your computer and use it in GitHub Desktop.
Save vinilios/280537 to your computer and use it in GitHub Desktop.
uwsgi update on code change
#!/usr/bin/python
import os, sys, subprocess
from pyinotify import *
# the watch manager stores the watches and provide operations on watches
wm = WatchManager()
# watched events
mask = IN_DELETE | IN_CREATE | IN_MODIFY
class DirChanged(ProcessEvent):
uwsgi_process = 'uwsgi26'
def uwsgi_graceful_restart(self):
print "updating uwsgi..."
retcode = subprocess.call(["killall","-SIGHUP","uwsgi26"])
print retcode
def process_IN_CREATE(self, event):
print "CREATED: " + event.path + "/" + event.name
self.uwsgi_graceful_restart()
def process_IN_DELETE(self, event):
print "DELETED: " + event.path + "/" + event.name
self.uwsgi_graceful_restart()
def process_IN_MODIFY(self, event):
print "MODIFIED: " + event.path + "/" + event.name
self.uwsgi_graceful_restart()
print "watching %s for changes" % os.path.abspath(sys.argv[1])
wdd = wm.add_watch(os.path.abspath(sys.argv[1]), mask, rec=True)
notifier = Notifier(wm, DirChanged())
while True: # loop forever
try:
# process the queue of events as explained above
notifier.process_events()
if notifier.check_events():
# read notified events and enqeue them
notifier.read_events()
# you can do some tasks here...
except KeyboardInterrupt:
# destroy the inotify's instance on this interrupt (stop monitoring)
notifier.stop()
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment