如何创建配置文件并告诉Gunicorn使用它?

Kri*_*abo 3 python gunicorn

我的应用程序运行良好但后来我改变了一些东西,现在它有时可以"回想"超过30秒然后再回到我身边.问题是Gunicorn在30秒后超时:

[2016-03-28 18:25:52 +0000] [3] [CRITICAL] WORKER TIMEOUT (pid:8)
2016-03-28T18:25:52.625220+00:00 app[web.1]:
[2016-03-28 18:25:52 +0000] [8] [INFO] Worker exiting (pid: 8)
Run Code Online (Sandbox Code Playgroud)

现在,我做了一些研究,我知道我需要为Gunicorn创建一个配置文件并发出命令来覆盖Gunicorn的超时默认值,如下所示: TIMEOUT=120 但是我该怎么做?我的意思是,我如何告诉Gunicorn,例如,gunicorn_config.txt并尊重我在那里制定的法律?

Aar*_*sen 5

配置文件可以写为INI文件或Python文件.如果您正在使用Python文件(这是我推荐的),请将其放入其中:

timeout = 120
Run Code Online (Sandbox Code Playgroud)

或者,如果要使用INI文件:

[server:main]
timeout = 120
Run Code Online (Sandbox Code Playgroud)

然后,当你运行Gunicorn时,添加一个-c选项告诉Gunicorn你的配置文件在哪里,如下所示:

gunicorn -c config.py ...
Run Code Online (Sandbox Code Playgroud)

请参阅此文件以获取可在配置文件中使用的选项列表.


对于您的示例,您根本不需要配置文件.只需运行Gunicorn --timeout选项:

gunicorn --timeout 120 ...
Run Code Online (Sandbox Code Playgroud)

  • 在版本 19.4 中更改:从 Python 模块加载配置需要 `python:` 前缀。https://docs.gunicorn.org/en/stable/settings.html#settings (2认同)