【发布时间】:2014-10-22 14:12:46
【问题描述】:
我有一个 Flask 应用程序,我正试图过渡到通过 gunicorn 运行。我在这方面遇到了很多问题。这是我的应用程序的运行代码:
app.run(host=HOST, port=PORT, debug=DEBUG_FLAG)
首先,如果 DEBUG_FLAG == true,应用程序将永远不会真正启动,而只会继续重启,并且在本地点击它是行不通的。它只是一遍又一遍地这样做:
gunicorn analytics_service:app
* Running on http://127.0.0.1:5000/
* Restarting with reloader
* Running on http://127.0.0.1:5000/
* Restarting with reloader
* Running on http://127.0.0.1:5000/
* Restarting with reloader
如果我用 DEBUG_FLAG==False 启动它,它实际上会启动并处理一些请求,但仍会由于未知原因频繁中断和重新启动:
gunicorn analytics_service:app (env: BigQueryTest)
* Running on http://127.0.0.1:5000/
127.0.0.1 - - [28/Aug/2014 08:59:05] "GET /metrics/ctr?location=blah&start_date=2014-05-21&end_date=2014-06-01 HTTP/1.1" 200 -
127.0.0.1 - - [28/Aug/2014 08:59:15] "GET /metrics/ctr?location=blah&start_date=2014-05-21&end_date=2014-06-05 HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 64693)
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 649, in __init__
self.handle()
File "/Users/Eli/.virtualenvs/BigQueryTest/lib/python2.7/site-packages/werkzeug/serving.py", line 200, in handle
rv = BaseHTTPRequestHandler.handle(self)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 340, in handle
self.handle_one_request()
File "/Users/Eli/.virtualenvs/BigQueryTest/lib/python2.7/site-packages/werkzeug/serving.py", line 231, in handle_one_request
self.raw_requestline = self.rfile.readline()
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 447, in readline
data = self._sock.recv(self._rbufsize)
File "/Users/Eli/.virtualenvs/BigQueryTest/lib/python2.7/site-packages/gunicorn/workers/base.py", line 154, in handle_abort
sys.exit(1)
SystemExit: 1
----------------------------------------
* Running on http://127.0.0.1:5000/
* Running on http://127.0.0.1:5000/
* Running on http://127.0.0.1:5000/
* Running on http://127.0.0.1:5000/
* Running on http://127.0.0.1:5000/
如前所述,如果我通过 Flask 的本机服务器运行,一切正常。只有 gunicorn 才会出现问题。帮忙?
【问题讨论】:
-
有 gunicorn 配置/命令行吗?与此比较:flask.pocoo.org/docs/0.10/deploying/wsgi-standalone
-
无特殊配置。从
gunicorn analytics_service:app开始。现在所有的配置都是通过 Flask 完成的,只需要设置主机、端口和 debug_flag。
标签: python python-2.7 flask gunicorn