Skip to content

Instantly share code, notes, and snippets.

@davesque
Created December 9, 2013 18:36
Show Gist options
  • Save davesque/7878005 to your computer and use it in GitHub Desktop.
Save davesque/7878005 to your computer and use it in GitHub Desktop.
Autoreload script for local
#!/usr/bin/env python
"""
Auto-reload script for local uWSGI setups. Inspired by code in the
django.utils.autoreload module.
"""
import logging
import os
import time
from django.utils.autoreload import code_changed
LOG_FORMAT = '%(levelname)s:%(name)s:[%(asctime)s] %(message)s'
logger = logging.getLogger(__name__)
PID_FILE = '/usr/local/var/run/uwsgi.pid'
with open(PID_FILE, 'r') as f:
PID = int(f.read())
def poll_for_changes():
while True:
if code_changed():
logger.info('Changes detected in python module files, restarting uWSGI...')
os.kill(PID, 1)
time.sleep(1)
def main():
try:
poll_for_changes()
except KeyboardInterrupt:
pass
if __name__ == '__main__':
logging.basicConfig(format=LOG_FORMAT, level=logging.INFO)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment