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

问题描述

有关一个奇怪的原因,当我实例化的 BeautifulSoup 的Django的视图中的对象时,WSGI超时。任何帮助是pciated因为我敲我的头撞在墙上几个小时,无法找到这个问题的根源AP $ P $。

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

更新:这似乎是一个BeautifulSoup ,但没有soution。

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

推荐答案

各种第三方软件包为Python它们使用C扩展模块,这包括SciPy的,numpy的和Beautifulsoup,只会在Python主跨preTER工作并且不能在子帧间preters作为默认用途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.

<一个href=\"http://$c$c.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API\">http://$c$c.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,你会想开始使用守护进程模式,因为一些框架不允许多个实例在同一间preTER运行调查。这是Django的情况。因此,使用守护进程模式,因此每个在其自己的进程,并强制每个在各自的守护模式进程组主跨preTER运行。

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超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 04:47