3

我正在使用与 Python 3 和 Linux 服务器一起使用的 Tornado,当我编辑和保存一些文本或 XML 文件时,我希望 Tornado 能够自行重启。我查了文档,发现这里有autoreload模块和watch功能。

它似乎只适用于 pyo 文件。如果我希望它在某个 URI 被修改时重新加载,我该怎么办?

4

3 回答 3

5

Setting the debug flag to True in settings forces Tornado to reload whenever a file is modified or whenever a URI is changed in app.py (or where ever you have defined your handlers). Tornado also automatically reloads template files so any changes in there will be seen instantly.

    settings = {
                'debug':True,
               # other stuff
    }
    tornado.web.Application.__init__(self, handlers, **settings)
于 2013-07-26T13:36:04.123 回答
4

添加的文件必须是绝对路径。

def addwatchfiles(*paths):
    for p in paths:
        autoreload.watch(os.path.abspath(p))
addwatchfiles('config.xml')

config.xml 位于服务器的 python 文件开始的同一目录中。

于 2013-08-26T13:44:42.997 回答
1

你需要开启autoreload

tornado.autoreload.start()
tornado.autoreload.watch('myfile')

完整示例位于https://gist.github.com/renaud/10356841

于 2014-04-10T08:37:19.440 回答