源昌上的gunicorn autoreload

2024-05-11 14:30:31 发布

您现在位置:Python中文网/ 问答频道 /正文

最后,我将开发环境从runserver迁移到gunicorn/nginx。

将runserver的autoreload特性复制到gunicorn会很方便,因此当源代码更改时服务器会自动重新启动。否则,我必须使用kill -HUP手动重新启动服务器。

有没有办法避免手动重启?


Tags: 服务器环境源代码nginx特性手动autoreloadkill
3条回答

一个选项是使用--max-requests通过向启动选项添加--max-requests 1,将每个派生进程限制为只服务一个请求。每个新生成的进程都应该看到您的代码更改,在开发环境中,每个请求的额外启动时间应该可以忽略不计。

虽然这是个老问题,但只是为了一致性——因为19.0版gunicorn有^{}选项。 所以没有第三方工具需要更多。

Bryan Helmig提出了这个,我修改了它,使用run_gunicorn而不是直接启动gunicorn,这样就可以将这3个命令剪切并粘贴到django项目根文件夹中的shell中(激活了virtualenv):

pip install watchdog -U
watchmedo shell-command --patterns="*.py;*.html;*.css;*.js" --recursive --command='echo "${watch_src_path}" && kill -HUP `cat gunicorn.pid`' . &
python manage.py run_gunicorn 127.0.0.1:80 --pid=gunicorn.pid

相关问题 更多 >