【问题标题】:reload flag with uvicorn: can we exclude certain code?用 uvicorn 重新加载标志:我们可以排除某些代码吗?
【发布时间】:2023-04-10 10:27:01
【问题描述】:

在使用--reload 标志重新加载脚本时,是否可以排除某些部分代码?

uvicorn main:app --reload

用例:我有一个模型需要很长时间加载,所以我想知道是否有办法在重新加载时忽略该行代码。还是根本不可能?

【问题讨论】:

标签: python fastapi uvicorn


【解决方案1】:

更新

Uvicorn 现在支持在监视列表中包含/排除某些目录/文件。

  --reload-include TEXT           Set glob patterns to include while watching
                                  for files. Includes '*.py' by default, which
                                  can be overridden in reload-excludes.
  --reload-exclude TEXT           Set glob patterns to exclude while watching
                                  for files. Includes '.*, .py[cod], .sw.*,
                                  ~*' by default, which can be overridden in
                                  reload-excludes.

没有办法排除某些东西,但是您可以使用 --reload-dir 标志明确说明您想要查看的内容:

  --reload-dir TEXT               Set reload directories explicitly, instead
                                  of using the current working directory.

https://www.uvicorn.org/#command-line-options

【讨论】:

  • 您能否建议如何在保留重新加载功能的同时使用此方法排除 asterik-symbol.json?我试过:uvicorn main:app --reload-exclude 'asterik-symbol.json' 但是它产生了这个警告:警告:当前配置不会重新加载,因为并非所有条件都满足,请参阅文档。 (注意:我输入了 asterik-symbol 来代替没有在评论中显示的 asterik)
【解决方案2】:

我不相信这是可能的,当服务器重新加载时,它会将所有需要的文件从头开始加载到内存中。它不会保留上次启动的记忆。

【讨论】:

    猜你喜欢
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 2018-12-06
    • 2013-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多