1
當我做一個web應用程序使用torado + flask,我遇到了一個問題,當我向我的應用程序發送請求時,它對我沒有任何迴應,它總是等待。 當我發現問題時,我發現在我的服務器機器(linux)中有很多'close wait'。 我不知道如何解決這個問題,任何人都可以幫助我嗎? 這裏是我使用龍捲風代碼:龍捲風燒瓶關閉等待
#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()
除非您想將* wsgi/flask應用程序與原生龍捲風應用程序*組合起來,否則'FallbackHandler'是不必要的。但你說得對,在Tornado WSGIContainer中運行燒瓶通常是一個壞主意:http://www.tornadoweb.org/en/stable/wsgi.html#tornado.wsgi.WSGIContainer。如果你使用燒瓶,你應該使用gunicorn或uwsgi而不是龍捲風的http服務器。 –
絕對 - 在我的回答中,我只是假設你應該將Flask包裝在WSGI容器中進行生產。 –
謝謝你所有的答案。我會考慮使用gunicorn而不是龍捲風的http服務器。謝謝! – elina