sro*_*oss 54

我正在运行uwsgi版本1.9.5和选项

uwsgi --py-autoreload 1
Run Code Online (Sandbox Code Playgroud)

效果很好


Luk*_*lor 20

如果uwsgi使用命令参数进行配置,请传递--py-autoreload=1:

uwsgi --py-autoreload=1
Run Code Online (Sandbox Code Playgroud)

如果您正在使用.ini文件进行配置uwsgi和使用uwsgi --ini,请将以下内容添加到您的.ini文件中:

py-autoreload = 1
Run Code Online (Sandbox Code Playgroud)


Tag*_*gar 13

对于开发环境,您可以尝试使用--python-autoreload uwsgi的参数.查看源代码,它可能只在线程模式下工作(--enable-threads).

  • 这个对我有用.在我的`uwsgi.ini`文件中添加`python-autoreload = 1`可以重新加载!谢谢! (9认同)

ver*_*hio 10

你可以尝试使用supervisord作为你的Uwsgi应用程序的管理员.它还具有监视功能,可在"触摸"/修改文件或文件夹时自动重新加载进程.

你会在这里找到一个很好的教程:Flask + NginX + Uwsgi + Supervisord

  • 该链接不再可用 (2认同)

two*_*ter 5

开发模式Flask的自动重新加载功能实际上是由底层的Werkzeug库提供的.相关代码是werkzeug/serving.py- 值得一看.但基本上,主应用程序将WSGI服务器生成为一个子进程,每秒对每个活动.py文件进行一次统计,查找更改.如果它看到任何,则子进程退出,并且父进程再次启动它 - 实际上重新加载chages.

你无法在uWSGI层实现类似的技术.如果您不想使用stat循环,可以尝试使用底层OS file-watch命令.显然(根据Werkzeug的代码),pyinotify是错误的,但也许看门狗工作?尝试一些事情,看看会发生什么.

编辑:

在回应评论时,我认为这很容易重新实现.以您的链接提供的示例为基础,以及来自的代码werkzeug/serving.py:

""" NOTE: _iter_module_files() and check_for_modifications() are both
    copied from Werkzeug code. Include appropriate attribution if
    actually used in a project. """
import uwsgi
from uwsgidecorators import timer

import sys
import os

def _iter_module_files():
    for module in sys.modules.values():
        filename = getattr(module, '__file__', None)
        if filename:
            old = None
            while not os.path.isfile(filename):
                old = filename
                filename = os.path.dirname(filename)
                if filename == old:
                    break
            else:
                if filename[-4:] in ('.pyc', '.pyo'):
                    filename = filename[:-1]
                yield filename

@timer(3)
def check_for_modifications():
    # Function-static variable... you could make this global, or whatever
    mtimes = check_for_modifications.mtimes
    for filename in _iter_module_files():
        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:
            uwsgi.reload()
            return

check_for_modifications.mtimes = {} # init static
Run Code Online (Sandbox Code Playgroud)

这是未经测试的,但应该有效.