在Django视图中的BeautifulSoup使WSGI超时 [英] BeautifulSoup inside Django view makes WSGI timeout

查看:145
本文介绍了在Django视图中的BeautifulSoup使WSGI超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于奇怪的原因,当我在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

更新:这似乎是一个

Update: This seems to be a bug in BeautifulSoup, however there is no soution.

推荐答案

使用C扩展的Python的各种第三方软件包模块,其中包括scipy,numpy和Beautifulsoup,只能在Python主解释器中工作,默认情况下不能在子解释器中使用mod_wsgi。你可以在下面的链接中找到。

Various third party packages for Python which use C extension modules, and this includes scipy, numpy and Beautifulsoup, will only work in the Python main interpreter and cannot be used in sub interpreters as mod_wsgi by default uses. You can find that in below link.

http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API

您可以通过写下面的一行来解决这个问题在你的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超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆