Flask WSGI应用程序在导入nltk时挂起 [英] Flask WSGI application hangs when import nltk

查看:206
本文介绍了Flask WSGI应用程序在导入nltk时挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照这里的指示创建了一个onefile flask- app在ubuntu上用mod-wsgi部署到apache2。这一切工作正常使用原来的烧瓶应用程序。然而,当添加 import nltk 到烧瓶应用程序apache挂起(不500)。

我使用python 2.7和nltk 2.0.4 p>

似乎也有类似的问题。设置

  WSGIApplicationGroup%{GLOBAL} 

在VirtualHost配置中似乎有所帮助。不过,我仍然得到相同的行为。有没有人遇到同样的问题?

以下是VirtualHost配置文件:

 < VirtualHost *:8080> 

#----配置VirtualHost默认值----

ServerAdmin jsmith@whoi.edu

DocumentRoot / home / bitnami / public_html / http

< Directory />
选项FollowSymLinks
AllowOverride无
< / Directory>

< Directory / home / bitnami / public_html / http />
选项索引FollowSymLinks MultiViews
AllowOverride None
允许,拒绝
所有
允许< / Directory>

----配置WSGI监听器----

WSGIDaemonProcess flaskapp user = www-data group = www-data processes = 1 threads = 5
WSGIScriptAlias / flasktest1 /home/bitnami/public_html/wsgi/flasktest1.wsgi

< Directory / home / bitnami / public_html / http / flasktest1>
WSGIProcessGroup flaskapp
WSGIApplicationGroup%{GLOBAL}
命令拒绝,允许
允许所有的
< / Directory>

#----配置日志记录----

ErrorLog /home/bitnami/public_html/logs/error.log
LogLevel警告
CustomLog /home/bitnami/public_html/logs/access.log combined



下面是修改后的烧瓶代码

 #!/ usr / bin / python 
from flask进口烧瓶

进口nltk
app =烧瓶(__ name__)
@ app.route('/')
def home():
返回< html>
< h2>来自测试应用程序1的Hello< / h2>
< / html>

@ app.route '/< foo>')
def foo(foo):
return< html>
< h2>测试应用程序1< / 2>
< ; h3> /%s< / h3>
< / html>%foo

if __name__ =='__main__':
我们在__main__范围?启动测试服务器。
app.run(host ='0.0.0.0',port = 5000,debug = True)


解决方案



 < Directory / home / bitnami / public_html / HTTP / flasktest1> 
WSGIProcessGroup flaskapp
WSGIApplicationGroup%{GLOBAL}
命令拒绝,允许
允许所有的
< / Directory>

应该是:

 < Directory / home / bitnami / public_html / http> 
WSGIProcessGroup flaskapp
WSGIApplicationGroup%{GLOBAL}
命令拒绝,允许
允许所有的
< / Directory>

因为您既不在守护进程模式下运行您的应用程序,也不在主解释器中运行您的应用程序,

那么Directory指令与上面的同一个目录的指令冲突,所以合并它们。



如果使用mod_wsgi 3.0或更高版本,而不是计数,也许删除第二个目录块,并使用:

$ $ p $ $ $ $ $ c $ WSGIDaemonProcess flaskapp threads = 5
WSGIScriptAlias / flasktest1 /home/bitnami/public_html/wsgi/flasktest1.wsgi process-group = flaskapp application-group =%{GLOBAL}

请注意,processes = 1已被删除,因为这是默认设置,它意味着您可能不想要的其他内容。您也不需要设置用户/组,因为它将自动以Apache用户身份运行。


I followed the instructions here to create a onefile flask-app deployed to apache2 with mod-wsgi on ubuntu. That all works fine when using the original flask app. However, when adding import nltk to the flask app apache hangs (no 500).

I use python 2.7 and nltk 2.0.4

Others seem to have had similar problems with other packages. Setting

WSGIApplicationGroup %{GLOBAL}

in the VirtualHost configuration seemed to have helped. However, I still get the same behavior. Did anybody run into the same issue? Thanks for the help!

Here is the VirtualHost Configuration file:

<VirtualHost *:8080>

    # ---- Configure VirtualHost Defaults ----

    ServerAdmin jsmith@whoi.edu 

    DocumentRoot /home/bitnami/public_html/http

    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>

    <Directory /home/bitnami/public_html/http/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            Allow from all
    </Directory>

    # ---- Configure WSGI Listener(s) ----

    WSGIDaemonProcess flaskapp user=www-data group=www-data processes=1 threads=5
    WSGIScriptAlias /flasktest1 /home/bitnami/public_html/wsgi/flasktest1.wsgi 

    <Directory /home/bitnami/public_html/http/flasktest1>
            WSGIProcessGroup flaskapp
            WSGIApplicationGroup %{GLOBAL}
            Order deny,allow
            Allow from all
    </Directory>

    # ---- Configure Logging ----

ErrorLog /home/bitnami/public_html/logs/error.log
LogLevel warn
CustomLog /home/bitnami/public_html/logs/access.log combined

Here is the modified flask code

#!/usr/bin/python
from flask import Flask

import nltk
app = Flask(__name__)
@app.route('/')
def home():
    return """<html>
    <h2>Hello from Test Application 1</h2>
    </html>"""

@app.route('/<foo>')
def foo(foo):
    return """<html>
    <h2>Test Application 1</2>
    <h3>/%s</h3>
    </html>""" % foo

if __name__ == '__main__':
    "Are we in the __main__ scope? Start test server."
    app.run(host='0.0.0.0',port=5000,debug=True)

解决方案

Where you have:

<Directory /home/bitnami/public_html/http/flasktest1>
        WSGIProcessGroup flaskapp
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
</Directory>

it should be:

<Directory /home/bitnami/public_html/http>
        WSGIProcessGroup flaskapp
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
</Directory>

as you are neither running your app in daemon mode or in the main interpreter because of the directives being in the wrong context.

That Directory directive then conflicts with one for same directory above so merge them.

If using mod_wsgi 3.0 or later count instead perhaps drop that second Directory block and use:

WSGIDaemonProcess flaskapp threads=5
WSGIScriptAlias /flasktest1 /home/bitnami/public_html/wsgi/flasktest1.wsgi process-group=flaskapp application-group=%{GLOBAL}

Note that processes=1 has been dropped as that is the default and setting it implies other things you likely don't want. You also don't need to set user/group as it will automatically run as the Apache user anyway.

这篇关于Flask WSGI应用程序在导入nltk时挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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