You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让uWSGI服务器在应用加载抛出异常时停止运行?

解决方案

在uwsgi.ini的[uwsgi]配置块中添加respawn-retry-limit = 0参数,修改后的配置如下:

[uwsgi]
http = 0.0.0.0:9090
master = true
processes = 1
gevent = 8
listen = 4096
buffer-size = 65535
uid = %u
gid = %g
; emperor = 1 does not work too
lazy = true
lazy-app = false
need-app = true
module = wsgi_run
die-on-term = true
sharedarea = 1
ignore-signpipe = true
harakiri-verbose = true
memory-report = true
log-master = true
# 限制启动失败后的重试次数为0,直接退出服务
respawn-retry-limit = 0

原理说明

  • 默认情况下,uWSGI会无限尝试重启启动失败的worker进程,导致陷入循环。
  • respawn-retry-limit = 0 配置表示当worker加载应用失败时,不进行任何重试,直接终止整个uWSGI服务。
  • 配合已启用的need-app = true,确保应用必须加载成功才能让worker正常运行,一旦加载失败立即触发终止逻辑。

若需要完全禁用所有worker的重启(包括运行中意外崩溃的情况),也可以使用no-respawn参数,但respawn-retry-limit更灵活,仅限制启动阶段的重试行为,更贴合当前场景需求。


内容的提问来源于stack exchange,提问作者rzlvmp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 08:24:56