mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import logging
|
|
import os
|
|
import signal
|
|
import sys
|
|
|
|
def on_starting(server):
|
|
# use server hook to patch socket to allow worker reloading
|
|
from gevent import monkey
|
|
monkey.patch_socket()
|
|
|
|
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)
|