Django Webfaction'从守护进程读取响应头时超时'

时间:2016-11-03 23:54:48

标签: django python-2.7 mod-wsgi webfaction

我在Webfaction上托管的生产服务器上的Django应用程序工作正常,直到我在将更改推送到settings.py文件后尝试重新启动它。我跑了

apache2/bin/restart
像往常一样。然后我尝试在浏览器上访问我的应用程序,然后我得到了504网关超时。我查看了mod_wsgi日志并看到了这个:

[Thu Nov 03 23:46:53.605625 2016] [wsgi:error] [pid 8027:tid 139641332168448]
[client 127.0.0.1:34570] Timeout when reading response headers from daemon 
process 'myapp' : /home/<me>/webapps/<myapp>/<ProjectName>/<myapp>/wsgi.py

这是什么意思,我该如何解决?我在settings.py文件中唯一更改的是移动一些变量名称。我仍然可以使用

成功地与应用互动
python2.7 manage.py shell

但我无法在网上找到它,也不能使用API​​。

编辑:这是我的wsgi.py文件:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "<myapp>.settings")

application = get_wsgi_application()

5 个答案:

答案 0 :(得分:17)

Python C扩展模块(如numpy)在mod_wsgi下使用时会导致超时。在https://serverfault.com/a/514251/109598

可以找到问题的明确解释(直接来自mod_wsgi的作者)

如果这听起来可能是您问题的原因,那么解决方案可能很简单 - 将以下内容添加到您的httpd.conf中:

WSGIApplicationGroup %{GLOBAL}

确保在进行更改后重新启动Apache实例。

答案 1 :(得分:1)

尝试在print("You decide it's time to look for a way out of this place. You consider travelling upstream to investigate where the wallet came from. You also remember being told that all rivers will eventually lead to a town or village.") direction = input("Do you travel a)upstream or b)downstream? >") if direction == "upstream" or direction == "Upstream" or direction == "Up" or direction == "up" or direction == "travel upstream" or direction == "Travel upstream": print("You travel upstream") elif direction == "downstream" or direction == "Downstream" or direction == "Down" or direction == "down" or direction == "travel downstream" or direction == "Travel Downstream": print("You travel downstream. You walk for hours but the river does not lead anywhere. It gets dark and you can no longer find your way. You decide to rest until morning.") print("You are suddenly woken from your sleep by a familiar voice. It's your", spouse+"!") print(spouse_name.upper()+":", '"'+name_f+"!?",'What are you doing here?' reply = input("Enter 1 for 'What are you doing here??' Enter 2 for 'I don't know, I just woke up here' >") if reply == '1': print(name_f.upper()+':',"What are you doing here??") print(name_f.upper()+':',"I elif reply == '2': print(name_f.upper()+':',"I don't know, I just woke up here") print(name_f.upper()+':',"I don't remember anything, I don't remember how I got here" print(spouse_name.upper()+":", "How are you still alive?" print(name_f.upper()=':', spouse_name+',','what are you talking about??') print("before you have time to realise what's going on,", spouse,"pulls out a gun and shoots you in the head") print("GAME OVER") 中增加Timeout指令,在Apache 2.4中默认为60秒。例如:

httpd.conf

答案 2 :(得分:0)

这是我找到问题根源的方法。

python manage.py showmigrations

我的应用无法访问数据库服务器,因此最终会超时。运行manage.py,我可以在控制台上看到错误消息。

答案 3 :(得分:0)

在我的情况下(Python 3.6),mimetypes模块导致了此问题。我没有对此进行进一步调查,但是删除了对mimetypes.guess_type的调用就解决了这个问题。该调用是在相关的Django视图函数中进行的。

答案 4 :(得分:0)

我遇到了同样的问题,因为运行 wsgi 进程的用户的主目录在服务器升级期间的某个时刻变得不可用。

这可能对某人有所帮助。