本文介绍了Flask 应用程序“以统计数据重新启动"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一些 Flask 应用程序,但在我的最新项目中,我注意到开发模式有些奇怪.终端中通常显示的消息的第二行始终为:

I've built a few Flask apps, but on my latest project I noticed something a little strange in development mode. The second line of the usual message in the terminal which always reads:

 * Running on http://127.0.0.1:5000/
 * Restarting with reloader

已被替换为:

 * Restarting with stat

我认为我没有做任何不同的事情,事实上,我首先克隆了一个我使用过很多次的入门套件项目,它本身并没有表现出这种行为.我还注意到这个项目稳定地消耗了大约 15% 的 CPU,而我的另一个项目几乎没有.

I don't think I've done anything different, in fact, I started by cloning a starter-kit project that I have used many times, which itself, does not display this behavior. I also notice that this project consumes about 15% CPU steadily, whereas my other project are barely a blip.

知道为什么会这样吗?

推荐答案

检查您的 Werkzeug 版本.0.10 版刚刚发布,重新加载器进行了大量更改.一个变化是使用了默认的轮询重新加载器;旧的 pyinotify 重载器显然不准确.如果您想要更高效的轮询,请安装 watchdog 包.您可以查看与此相关的代码 .

Check your version of Werkzeug. Version 0.10 was just released and numerous changes went into the reloader. One change is that a default polling reloader is used; the old pyinotify reloader was apparently inaccurate. If you want more efficient polling, install the watchdog package. You can see the code related to this here.

当 Werkzeug 找不到看门狗时,它使用 stat 重载器,否则它使用重载器看门狗使用的任何重载器,这可能因平台而异.此消息只是为了让您知道正在使用哪个.

When Werkzeug can't find watchdog, it uses the stat reloader, otherwise it uses whatever reloader watchdog uses, which can vary by platform. This message is just so you know which one is in use.

看门狗可能与 gevent 不兼容.如果您使用 gevent 并且在使用 Watchdog 时遇到重载器问题,请查看 这个 GitHub 问题.

Watchdog may not be compatible with gevent. If you're using gevent and having issues with the reloader when using Watchdog, check this GitHub issue.

这篇关于Flask 应用程序“以统计数据重新启动"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:05