我正试图将一个项目从开发转移到生产。(在开发阶段,我只使用
Flask
,现在我在后面运行它
Gunicorn
具有
Nginx
.)
我在服务特定页面时遇到问题,
songs.html
.
页面使用虚拟变量正确加载(
jukebox = [whatever]
)但在现实生活中,我使用的是发电机,就像这样:
playlist= query_playlist(p)
jukebox = next(playlist)
return render_template('songs.html',
jukebox=jukebox)
这个函数需要一段时间(比如2s)才能返回结果。。。但并没有提供结果,并且在返回结果后,进程将挂起。
我这样运行应用程序:
(appenv)$gunicorn -c gconfig.py app:app
wsgi。ppy公司
from app import app as application
if __name__ == "__main__":
application.run(host='0.0.0.0')
gconfig。py:
workers = 16
worker_class = 'sync'
worker_connections = 1000
timeout = 120 # changed this from 30 up
keepalive = 2
nginx公司。形态
(
brew
(安装)
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://127.0.0.1:8000/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
如果我使用
python app.py
,返回开发阶段:
if __name__ == '__main__':
app.run(use_reloader=True, threaded=True, debug=True)
至少我得到了以下回溯:
Error on request:
Traceback (most recent call last):
File "/Users/me/Documents/Code/Apps/app/appenv/lib/python2.7/site-packages/werkzeug/serving.py", line 270, in run_wsgi
execute(self.server.app)
File "/Users/me/Documents/Code/Apps/app/appenv/lib/python2.7/site-packages/werkzeug/serving.py", line 261, in execute
write(data)
File "/Users/me/Documents/Code/Apps/app/appenv/lib/python2.7/site-packages/werkzeug/serving.py", line 236, in write
self.send_header('Server', self.version_string())
File "/Users/me/anaconda2/lib/python2.7/BaseHTTPServer.py", line 412, in send_header
self.wfile.write("%s: %s\r\n" % (keyword, value))
IOError: [Errno 32] Broken pipe
那么有人知道如何解决这个问题吗?
编辑
我得到了相同的回溯,即使结果需要2秒才能处理。