gunicorn捕获请求,但只有一个烧瓶路线正在工作

时间:2016-05-30 15:00:50

标签: python flask gunicorn

嗨stackoverflow人,

我使用gunicorn部署我的flask应用,这是我的配置文件:

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid user
setgid www-data

exec gunicorn  --log-level=DEBUG  --workers $(( 2 * `cat /proc/cpuinfo | grep 'core id' | wc -l` + 1 )) --limit-request-line 0 --bind unix:my_app.sock --timeout=10 -m 007 main:app

我将这个gunicorn文件用于其他几个项目,它始终有效,但这次它的行为不同。

当我查看日志文件时,我可以看到我的请求:

[29878] [DEBUG] GET /event
[28948] [DEBUG] GET /

但什么都没发生。 只有一条路线正在工作,它是我主文件中的一条路线

这里是文件main.py

from __init__ import app
from auth import authentification
from auth.authentification import auth
from route.route import api
from route.event import EventClass
from route.profile import Profile_route
from route.report import Report
from route.search import Search
from flask import Flask, jsonify
from extensions import db, mail, login_manager
from config import BaseConfig, DefaultConfig
from flask.ext.mail import Message
import base64, time, os
from werkzeug.serving import BaseRequestHandler
from flask_swagger import swagger

class MyFancyRequestHandler(BaseRequestHandler):
    """Extend werkzeug request handler to suit our needs."""
    def handle(self):
        self.fancyStarted = time.time()
        rv = super(MyFancyRequestHandler, self).handle()
        return rv

    def send_response(self, *args, **kw):
        self.fancyProcessed = time.time()
        super(MyFancyRequestHandler, self).send_response(*args, **kw)

    def log_request(self, code='-', size='-'):
        duration = int((self.fancyProcessed - self.fancyStarted) * 1000)
        self.log('info', '"{0}" {1} {2} [{3}ms]'.format(self.requestline, code, size, duration))

DEFAULT_BLUEPRINTS = (
    auth,
    api
)

@app.route("/")
def hello():
    return "This route is working !"

def configure_swagger(app):
    from flasgger import Swagger
    Swagger(app)


def configure_auth():
    authentification.Auth()

def configure_app(app):
    """Different ways of configurations."""

    if app.debug:
        # http://flask.pocoo.org/docs/api/#configuration
        app.config.from_object(DefaultConfig)
    else:
        app.config.from_object(BaseConfig)

def configure_blueprints(app, blueprints):
    """Configure blueprints"""
    for blueprint in blueprints:
        app.register_blueprint(blueprint)

def configure_extensions(app):
    # flask-sqlalchemy
    db.init_app(app)

    # flask-mail
    mail.init_app(app)

    login_manager.setup_app(app)

    #event
    EventClass()

    #report
    Report()

    #search
    Search()

    #profile
    Profile_route()

if __name__ == "__main__":
    blueprints = DEFAULT_BLUEPRINTS
    configure_blueprints(app, blueprints)
    configure_app(app)
    configure_extensions(app)
    configure_auth()
    configure_swagger(app)
    app.run(host="0.0.0.0", debug=True, request_handler=MyFancyRequestHandler)

因此@api.route("/")在尝试访问它时正在工作,但在此文件(EventClass,Route,Search,...)之外声明的所有路径似乎都无法访问。当我尝试向main.py添加另一条路线时,路线变得可以访问。

知道我做错了什么吗?

更新:

如果我单独运行我的flask应用python3 main.py,则每条路线都可用。

0 个答案:

没有答案