Python Flask 应用程序“使用统计数据重新启动”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28241989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:58:59  来源:igfitidea点击:

Flask app "Restarting with stat"

pythonflask

提问by domoarigato

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:

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

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

has been replaced by:

已被替换为:

 * Restarting with stat

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.

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

Any ideas why this is happening?

任何想法为什么会发生这种情况?

采纳答案by davidism

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 watchdogpackage. You can see the code related to this here.

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

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

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



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.

看门狗可能与 gevent 不兼容。如果您使用 gevent 并且在使用 Watchdog 时遇到重新加载器的问题,请查看此 GitHub 问题

回答by Cyrus Dsouza

Use run(use_reloader=False)to disable the reloader.

使用run(use_reloader=False)禁用reloader。

It gave me some problems where it wasn't able to find my server file when it restarted. This did the trick. It executed just once and everything worked. Quite odd.

它给了我一些问题,它在重新启动时无法找到我的服务器文件。这成功了。它只执行了一次,一切正常。很奇怪。

回答by NickJason

If you run with app.run(debug=True), it will run the reloader as part of debug mode. If you don't want to use debug mode, pass debug=Falseor don't pass it at all.

如果您使用 运行app.run(debug=True),它将作为调试模式的一部分运行重新加载器。如果您不想使用调试模式,请通过debug=False或根本不通过。

回答by maganoegi

my filename was __main__.py and I exported it as such: export FLASK_APP=__main__.py Upon changing the name to app.py and reexporting it, it worked.

我的文件名是 __main__.py,我将其导出为: export FLASK_APP=__main__.py 将名称更改为 app.py 并重新导出后,它起作用了。