mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Added an example reloader config to the examples.
Thanks to thomasst on GitHub for the sample. Closes #54
This commit is contained in:
parent
e12e77765a
commit
80f4d17122
3
THANKS
3
THANKS
@ -11,4 +11,5 @@ Xavier Grangier <grangier@gmail.com>
|
||||
Sergey Shepelev <temotor@gmail.com>
|
||||
Chris Dent <chris.dent@gmail.com>
|
||||
Matt Good <matt@matt-good.net>
|
||||
Randall Leeds <randall.leeds@gmail.com>
|
||||
Randall Leeds <randall.leeds@gmail.com>
|
||||
thomasst <http://github.com/thomasst>
|
||||
|
||||
31
examples/example_gevent_reloader.py
Normal file
31
examples/example_gevent_reloader.py
Normal file
@ -0,0 +1,31 @@
|
||||
import gevent
|
||||
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)
|
||||
|
||||
gevent.Greenlet.spawn(monitor)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user