我在生产服务器上使用 django 1.8 + uwsgi + nginx。uwsgi 处于帝王模式。我在 myapp/settings.py 中导入了 uwsgi python 模块,以便在修改代码时启用自动重载。据我了解,此 python 模块仅在 python 线程由 uwsgi worker 生成时才可用于导入。当我尝试手动使用 manage.py collectstatic 时,是导入 settings.py 然后无法导入 uwsgi.py。
有没有办法在使用 uwsgi python 模块的同时仍然能够使用 manage.py ?
我用来启用自动重载的代码(在 myapp/sttings.py 中):
import uwsgi
from uwsgidecorators import timer
from django.utils import autoreload
@timer(3)
def change_code_gracefull_reload(sig):
if autoreload.code_changed():
uwsgi.reload()