Flask WSGI application hangs when import nltk

随声附和 提交于 2019-12-22 05:01:14

问题


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)

回答1:


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.



来源:https://stackoverflow.com/questions/13895889/flask-wsgi-application-hangs-when-import-nltk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!