I'm getting inconsistent code-reloading behavior, with a Django 1.3 application and gunicorn 0.12.1, running inside a virtualenv.
我得到了不一致的代码重载行为,Django 1.3应用程序和gunicorn 0.12.1在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.
Gunicorn没有正确地重载我的应用程序,即使重新启动了特定的Gunicorn进程PID。当我运行一个基本的runserver(通过Django,通过管理)。这不是问题。
When I remove and recreate my virtualenv, gunicorn runs as expected with the new code.
当我移除并重新创建我的virtualenv时,gunicorn以新的代码运行。
Is there a Python cache or something? I also tried to remove all *.pyc
files.
有Python缓存还是别的什么?我还试图删除所有*。佩克文件。
2 个解决方案
#1
6
Try this:
试试这个:
$ kill -HUP masterpid
Also, have a look at some of the notes at the bottom of the following post.
另外,请阅读下面文章底部的一些注释。
#2
4
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.
我也遇到了这个问题的各种变体——正如Pokomy在一篇文章中建议的那样,用HUP信号杀死gunicorn master进程似乎很管用。
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:
如果您使用python监控模块,则可以轻松地在文件上设置自动重新加载;这个设置实际上是很容易理解的,所以这里有一个来自我的开发主管的代码片段。配置文件:
[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)
(注意,我把斜线放在那个示例中,然后是实际上不在conf文件中的新行——我插入这些新行是为了便于阅读;我不确定这是否有效
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".
第一个程序是gunicorn进程,为了使用Werkzeug调试器,我在开发期间在一个线程中运行这个进程。第二部分是有趣的部分:该命令说,“如果文件的后缀与此列表中的一个相匹配,则在目录树中的文件中发生更改时,杀死gunicorn PID文件指定的进程”。
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.
对包括我在内的许多人来说,这是一种魅力。如果你不知道的话,看门狗很有用,值得一看。
#1
6
Try this:
试试这个:
$ kill -HUP masterpid
Also, have a look at some of the notes at the bottom of the following post.
另外,请阅读下面文章底部的一些注释。
#2
4
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.
我也遇到了这个问题的各种变体——正如Pokomy在一篇文章中建议的那样,用HUP信号杀死gunicorn master进程似乎很管用。
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:
如果您使用python监控模块,则可以轻松地在文件上设置自动重新加载;这个设置实际上是很容易理解的,所以这里有一个来自我的开发主管的代码片段。配置文件:
[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)
(注意,我把斜线放在那个示例中,然后是实际上不在conf文件中的新行——我插入这些新行是为了便于阅读;我不确定这是否有效
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".
第一个程序是gunicorn进程,为了使用Werkzeug调试器,我在开发期间在一个线程中运行这个进程。第二部分是有趣的部分:该命令说,“如果文件的后缀与此列表中的一个相匹配,则在目录树中的文件中发生更改时,杀死gunicorn PID文件指定的进程”。
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.
对包括我在内的许多人来说,这是一种魅力。如果你不知道的话,看门狗很有用,值得一看。