Created
September 14, 2010 15:27
-
-
Save tmc/579207 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import logging | |
import os | |
import signal | |
import sys | |
def when_ready(server): | |
def monitor(): | |
modify_times = {} | |
while True: | |
for module in sys.modules.values(): | |
path = getattr(module, "__file__", None) | |
if not path: continue | |
if path.endswith(".pyc") or path.endswith(".pyo"): | |
path = path[:-1] | |
try: | |
modified = os.stat(path).st_mtime | |
except: | |
continue | |
if path not in modify_times: | |
modify_times[path] = modified | |
continue | |
if modify_times[path] != modified: | |
logging.info("%s modified; restarting server", path) | |
os.kill(os.getpid(), signal.SIGHUP) | |
modify_times = {} | |
break | |
gevent.sleep(1) | |
import gevent | |
gevent.spawn(monitor) | |
worker_class = 'gevent' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment