Created
February 18, 2013 18:12
-
-
Save shnjp/4979363 to your computer and use it in GitHub Desktop.
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
""" | |
uwsgiのエントリポイントの中でコレを実行すれば、ファイルに変更があった時にリロードする。 | |
""" | |
import uwsgi | |
from uwsgidecorators import timer | |
from werkzeug.serving import _iter_module_files, _log | |
import os | |
# TODO: uwsgi.optsから読み込む | |
interval = 1 | |
extra_files = None | |
mtimes = {} | |
@timer(1) | |
def watch_files(*args): | |
from itertools import chain | |
for filename in chain(_iter_module_files(), extra_files or ()): | |
try: | |
mtime = os.stat(filename).st_mtime | |
except OSError: | |
continue | |
old_time = mtimes.get(filename) | |
if old_time is None: | |
mtimes[filename] = mtime | |
continue | |
elif mtime > old_time: | |
_log('info', ' * Detected change in %r, reloading' % filename) | |
uwsgi.reload() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment