Gunicorn 未重新加载 Django 应用程序

发布于 2024-11-02 17:20:23 字数 288 浏览 6 评论 0原文

我在 virtualenv 内运行 Django 1.3 应用程序和 Gunicorn 0.12.1,代码重新加载行为不一致。

即使重新启动特定的 Gunicorn 进程 PID,Gunicorn 也无法正确重新加载我的应用程序。当我运行基本的 runserver(通过 Django,通过 manage.py 命令)时,这不是问题。

当我删除并重新创建 virtualenv 时,gunicorn 使用新代码按预期运行。

有Python缓存之类的吗?我还尝试删除所有 *.pyc 文件。

I'm getting inconsistent code-reloading behavior, with a Django 1.3 application and gunicorn 0.12.1, running inside a virtualenv.

Gunicorn does not reload my application properly, even with a restart of the specific gunicorn process PID. When I run a basic runserver (through Django, via the manage.py command) this is not an issue.

When I remove and recreate my virtualenv, gunicorn runs as expected with the new code.

Is there a Python cache or something? I also tried to remove all *.pyc files.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北方的韩爷 2024-11-09 17:20:24

我也遇到了这个问题的变体 - 正如 Pokomy ​​先生链接的文章中所建议的那样,用 HUP 信号杀死 Gunicorn 主进程似乎可以解决问题。

如果使用 python watchdog 模块,可以轻松设置文件保存时的自动重新加载;这个设置实际上是不言自明的,所以这是我的开发supervisord.conf文件中的一个片段:(

[program:ost2]
autostart=true
command=/usr/local/share/python/gunicorn --debug\
-c /Users/fish/Dropbox/ost2/ost2/utils/gunicorn/ost2-debug.py wsgi_debug
directory=/Users/fish/Dropbox/ost2/ost2
priority=500
; (etc)

[program:ost2-reloader]
autostart=true
autorestart=false
directory=/tmp
command=/usr/local/share/python/watchmedo shell-command\ 
--patterns="*.py;*.txt;*.html;*.css;*.less;*.js;*.coffee"\
-R --command='kill -HUP $(cat /usr/local/gunicorn/gunicorn.pid)'\
/Users/fish/Dropbox/ost2/ost2/
priority=996
; (etc)

注意,我在该示例中将斜杠放在了实际上不在conf文件中的换行符之前——我插入了这些换行符以方便阅读;我不确定这是否有效)

第一个程序是gunicorn进程,我在开发过程中在单线程中运行它,以便使用Werkzeug调试器。第二部分是有趣的一点:该命令说,“只要该目录树中的文件发生更改,如果文件的后缀与此列表中的后缀匹配,则终止由 Gunicorn PID 文件指定的进程”。

对于包括我在内的许多人来说,它就像一种魅力。如果您不知道的话,watchdog 非常有用,并且就其本身而言值得一看。

I ran into variations of this problem as well -- as advised in the article linked to by Mr. Pokomy, killing the gunicorn master process with a HUP signal seems to do the trick.

One can set up auto-reloading on file save easily, if you use the python watchdog module; the setup is actually pretty self-explanatory, so here's a snippet from my development supervisord.conf file:

[program:ost2]
autostart=true
command=/usr/local/share/python/gunicorn --debug\
-c /Users/fish/Dropbox/ost2/ost2/utils/gunicorn/ost2-debug.py wsgi_debug
directory=/Users/fish/Dropbox/ost2/ost2
priority=500
; (etc)

[program:ost2-reloader]
autostart=true
autorestart=false
directory=/tmp
command=/usr/local/share/python/watchmedo shell-command\ 
--patterns="*.py;*.txt;*.html;*.css;*.less;*.js;*.coffee"\
-R --command='kill -HUP $(cat /usr/local/gunicorn/gunicorn.pid)'\
/Users/fish/Dropbox/ost2/ost2/
priority=996
; (etc)

(N.B. I put the slashes in that sample before newlines that aren't actually in the conf file -- I inserted those newlines for legibility; I am not sure if that works IRL)

The first program is the gunicorn process, which I run in a single thread during development in order to use the Werkzeug debugger. The second part is the interesting bit: that command says, "kill the process specified by the gunicorn PID file whenever there's a change in a file in this directory tree if the file's suffix matches one from this list".

Works like a charm for many including me. If you don't know it, watchdog is very useful and is worth a look, in its own right.

梦幻的心爱 2024-11-09 17:20:23

试试这个:

$ kill -HUP masterpid

另外,看看 以下帖子

Try this:

$ kill -HUP masterpid

Also, have a look at some of the notes at the bottom of the following post.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文