[英]How to change and reload python code in waitress without restarting the server?
I am using waitress to serve the web application content like.我正在使用女服务员来提供 Web 应用程序内容,例如。
waitress-serve --port=8000 myapp:application
While developing, as I change code, I continuously had to restart the waitress-serve to see my changes.在开发过程中,当我更改代码时,我必须不断地重新启动女服务员才能看到我的更改。 Is there a standard way I can automate this?有没有标准的方法可以自动化这个?
I know this is an old question but I had a similar issue trying to enable hot reload functionality for my REST API using Falcon framework.我知道这是一个老问题,但我在尝试使用 Falcon 框架为我的 REST API 启用热重载功能时遇到了类似的问题。
Waitress does not monitor file changes but you could use hupper
on top of it. Waitress 不监视文件更改,但您可以在其上使用hupper
。 Pretty simple:很简单:
$ pip install hupper
$ hupper -m waitress --port=8000 myapp:application
It works on Windows too.它也适用于 Windows。
Based on the comment by @Dirk, I found the archive.org link to the snippet mentioned.根据@Dirk 的评论,我找到了指向提到的片段的 archive.org 链接。 I was able to get Waitress reloading by using Werkseug directly.我能够通过直接使用 Werkseug 重新加载 Waitress。 Using Werkzeug's decorator run_with_reloader
causes the app to restart whenever a Python file changes.使用 Werkzeug 的装饰器run_with_reloader
会导致应用程序在 Python 文件更改时重新启动。 (Werkzeug is used within Flask so it should be available). (Werkzeug 在 Flask 中使用,所以它应该可用)。
Additionally, the app.debug = True
line causes Flask to reload template files when they change.此外, app.debug = True
行会导致 Flask 在模板文件更改时重新加载它们。 So you may want both considering your particular situation.因此,考虑到您的特定情况,您可能希望两者兼而有之。
import werkzeug.serving
@werkzeug.serving.run_with_reloader
def run_server():
app.debug = True
waitress.serve(app, listen='127.0.0.1:4432')
if __name__ == '__main__':
run_server()
Once I had my server set up this way, it auto-reloaded the server whenever any file changed.一旦我以这种方式设置了我的服务器,它就会在任何文件更改时自动重新加载服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.