问题描述
出于奇怪的原因,当我在Django的视图中实例化一个 BeautifulSoup 对象时,WSGI超时。任何帮助都不胜感激,因为我正在撞上墙壁几个小时,找不到这个问题的根源。
For a strange reason when I instantiate a BeautifulSoup object inside Django's view, the WSGI timeout. Any help is appreciated as I am banging my head against the wall for hours and cannot find the root of this problem.
视图:
def index(request):
soup = BeautifulSoup('<b>Bold</b>') # Removing this line solve the proble
return HttpResponse('Hello')
Apache日志中的错误消息:
The error message in Apache log:
[wsgi:error] [pid 4014] [client 127.0.0.1:50892] Timeout when reading response headers from daemon process 'test.local': /htdocs/test/test/wsgi.py
更新:这似乎是一个
您可以通过写下面的一行来解决这个问题在你的conf文件中。
You can solve this by writing below line in your conf file.
WSGIApplicationGroup %{GLOBAL}
如果在同一台服务器上运行多个WSGI应用程序,则需要开始调查使用守护进程模式,因为某些框架不允许多个实例在同一解释器中运行。 Django就是这样。因此,使用守护进程模式,因此每个进程都在自己的进程中,并强制每个进程在其各自的守护程序进程组的主解释器中运行。
If running multiple WSGI applications on same server, you would want to start investigating using daemon mode because some frameworks don't allow multiple instances to run in same interpreter. This is the case with Django. Thus use daemon mode so each is in its own process and force each to run in main interpreter of their respective daemon mode process groups.
这篇关于在Django视图中的BeautifulSoup使WSGI超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!