Created
December 9, 2013 18:36
-
-
Save davesque/7878005 to your computer and use it in GitHub Desktop.
Autoreload script for local
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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