为什么 Django fcgi 会死掉?我怎样才能找到答案?
我使用 fcgi 和 Lighttpd 在 Linux 上运行 Django。服务器时不时地(大约一天一次)死掉。我正在使用 Django、Python 和 Lighttpd 的最新稳定版本。
我唯一能想到的是我的程序正在打开大量文件并执行大量外部进程,但我相当确定事情的这一面是无懈可击的。
查看错误和访问日志,没有发生任何异常情况(即负载没有高于正常水平)。在那些我遇到 Python 异常的情况下,这些异常会显示在 error.log 中,但是当崩溃发生时我什么也得不到。
有什么方法可以找出进程死亡的原因吗?缺少将日志语句放在每一行上吗?显然我无法重现这个,所以我不知道到底该去哪里查看。
编辑
这是 django 进程正在消亡。我正在使用 manage.py runfcgi daemonize=true method=threaded host=127.0.0.1 port=12345
运行服务器
I'm running Django on Linux using fcgi and Lighttpd. Every now and again (about once a day) the server just dies. I'm using the latest stable release of Django, Python and Lighttpd.
The only thing I can think of is that my program is opening a lot of files and executing a lot of external processes, but I'm fairly sure that side of things is watertight.
Looking at the error and access logs, there's nothing exceptional happening (i.e. load isn't above normal). On those occasions where I have had exceptions from Python, these have shown up in the error.log, but when this crash happens I get nothing.
Is there any way of finding out why the process died? Short of putting logging statements on every single line? Obviously I can't reproduce this so I don't know exactly where to look.
Edit
It's the django process that's dying. I'm running the server with manage.py runfcgi daemonize=true method=threaded host=127.0.0.1 port=12345
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以编辑
manage.py
将 stderr 重定向到文件,假设runfcgi
本身不执行此操作:You could edit
manage.py
to redirect stderr to a file, assumingrunfcgi
doesn't do that itself:这是在你的服务器上吗? (你拥有这个盒子吗?)。我在共享主机上遇到过这个问题,主机只是杀死了长进程。您知道您的 fcgi 是否收到 SIGTERM 信号吗?
Is this on your server? (do you own the box?). I've had that problem on shared hosting, and the host was just killing long processes. Do you know if your fcgi is receiving a SIGTERM?
也遇到过同样的问题。它们不仅会在没有警告或原因的情况下死亡,而且还会疯狂地泄漏,因为线程在没有主进程的情况下被卡住。我们通过每 5 分钟运行一个 cronjob 来解决这个问题,检查端口号是否已启动并正在运行,如果没有则重新启动。
顺便说一句,我们现在(缓慢迁移)放弃了 fcgi 并转向了 uwsgi。
Have had the same problems. Not only do they die without warning or reason they leak like crazy too with threads being stuck without a master process. We solved this problem by having a cronjob run every 5 minutes that checks if the port number is up and running and if not restart.
By the way, we've now (slowly migrating) given up on fcgi and moved over to uwsgi.