1

when i make a web application use torado+flask ,i meet a question that when i send a request to my application,it response nothing to me ,and its always await. when i find the problem,i found that there is many 'close wait' in my server machine(linux). i don't know how to resolve this question,can anybody help me? here is the code i use tornado:

#coding=utf-8
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer`enter code here`
from tornado.ioloop import IOLoop
from service import app #app is a flask in another file:app=Flask(__name__)
from config import SERVER_CONF
from appLog import logging


def startService():
    logging.info('start web,http://%s:%s/test'%(SERVER_CONF['IP'],SERVER_CONF['PORT']))
    try:
        http_server=HTTPServer(WSGIContainer(app))
        http_server.listen(SERVER_CONF['PORT'],address=SERVER_CONF['IP'])
        IOLoop.instance().start()
    except Exception as e:
        logging.error('start failed:')
        logging.error(e)


if __name__=='__main__':
    startService()
elina
  • 11
  • 1

1 Answers1

0

My understanding is that you need to use FallbackHandler, as described in this answer.

That being said, I would strongly recommend against using this approach -- Tornado includes an excellent microframework of its own, which integrates much better with the server and is in many ways superior to Flask. If using Flask is important I would recommend exploring a different ways to ensure concurrency (e.g. multiple instances behind a nginx load balancer), or even taking a look at Sanic, which is both asynchronous and very similar to Flask.

Community
  • 1
  • 1
Berislav Lopac
  • 16,656
  • 6
  • 71
  • 80
  • 1
    `FallbackHandler` is unnecessary unless you want to *combine* a wsgi/flask app with a native tornado one. But you're right that running flask in a Tornado WSGIContainer is generally a bad idea: http://www.tornadoweb.org/en/stable/wsgi.html#tornado.wsgi.WSGIContainer. If you're using flask you should probably use gunicorn or uwsgi instead of tornado's http server. – Ben Darnell Jan 08 '17 at 22:53
  • Absolutely -- in my answer I just assumed that you should wrap Flask in a WSGI container for production. – Berislav Lopac Jan 08 '17 at 23:02
  • Thanks all your answers. I'll consider use the gunicorn instead of tornado's http server.Thank you! – elina Feb 10 '17 at 04:38