Gunicorn 未重新加载 Django 应用程序
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也遇到了这个问题的变体 - 正如 Pokomy 先生链接的文章中所建议的那样,用
HUP
信号杀死 Gunicorn 主进程似乎可以解决问题。如果使用 python
watchdog
模块,可以轻松设置文件保存时的自动重新加载;这个设置实际上是不言自明的,所以这是我的开发supervisord.conf文件中的一个片段:(注意,我在该示例中将斜杠放在了实际上不在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:(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.试试这个:
另外,看看 以下帖子。
Try this:
Also, have a look at some of the notes at the bottom of the following post.