简体   繁体   English

如何在不重新启动服务器的情况下更改和重新加载女服务员的python代码?

[英]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.

相关问题 在不重新启动主脚本的情况下加载/重新加载Python中的一部分代码 - Load/reload a portion of code in Python without restarting main script Python 带女服务员的 Dash 服务器 - Python Dash server with waitress 如何在不重新启动应用程序的情况下自动重新加载 python 模块? - How to auto reload python module without restarting app? 有没有办法在没有重新启动服务器的情况下使用Tornado / Python部署新代码? - Is there a way to deploy new code with Tornado/Python without restarting the server? 如何在 Python Waitress 服务器上调试(500)内部服务器错误? - How to debug (500) Internal Server Error on Python Waitress server? 如何在不重新启动塔的情况下重新加载已修改的文件? - How to reload the modified files without restarting in pylons? 代码更改后,如何在不重启pdb的情况下重新开始调试? - After code change, how to start over debugging without restarting pdb? 如何设置Python Pyramid Waitress服务器的日志记录? - How to set up logging for a Python Pyramid Waitress server? 如何在不重新启动python解释器的情况下对模块进行更改? - How can I make a change to a module without restarting python interpreter? 如何避免对python文件中的每个更改重新启动apache服务器? - How to avoid restarting apache server for every change made in a python file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM