使用gunicorn在heroku上部署flask会导致R12超时问题

时间:2016-02-22 22:45:41

标签: python heroku flask gunicorn

在网上挖掘给我一些线索,可能是heroku对于某些构建有一些时间问题。然而另一个建议是明确地参数化端口,但我似乎仍然遇到这个问题。 localhost版本运行良好。

   stopping all processes with SIGTERM
    2016-02-22T22:36:36.687853+00:00 app[web.1]: [2016-02-22 22:36:36 +0000] [3] [INFO] Handling signal: term
    2016-02-22T22:36:42.845739+00:00 heroku[web.1]: Starting process with command `gunicorn login:app -b 0.0.0.0:7032 --timeout 90`
    2016-02-22T22:36:45.089125+00:00 app[web.1]: [2016-02-22 22:36:45 +0000] [3] [INFO] Listening at: http://0.0.0.0:7032 (3)
    2016-02-22T22:36:45.089254+00:00 app[web.1]: [2016-02-22 22:36:45 +0000] [3] [INFO] Using worker: sync
    2016-02-22T22:36:45.088398+00:00 app[web.1]: [2016-02-22 22:36:45 +0000] [3] [INFO] Starting gunicorn 19.3.0
    2016-02-22T22:36:45.166359+00:00 app[web.1]: [2016-02-22 22:36:45 +0000] [9] [INFO] Booting worker with pid: 9
    2016-02-22T22:36:45.093125+00:00 app[web.1]: [2016-02-22 22:36:45 +0000] [7] [INFO] Booting worker with pid: 7
    2016-02-22T22:36:46.242345+00:00 heroku[web.1]: Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM
    2016-02-22T22:36:46.242463+00:00 heroku[web.1]: Stopping remaining processes with SIGKILL
    2016-02-22T22:36:46.460542+00:00 heroku[web.1]: State changed from starting to up
    2016-02-22T22:36:47.319021+00:00 heroku[web.1]: Process exited with status 137

以下是Procfile

web: gunicorn login:app -b 0.0.0.0:$PORT --timeout 90 

这是__main__

login.py
if __name__ == '__main__':
  port = int(os.environ.get("PORT", 5000))
  app.run(debug=True, host='0.0.0.0', port=port)

问题是,应用配置是否正确。我还能做些什么来阐明这个问题。我似乎没有更多的粒度来解决这个错误。

这是我的requirements.txt

Flask==0.10.1
Flask-PyMongo==0.3.1
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.11.4
argparse==1.2.1
itsdangerous==0.24
mongoengine==0.8.7
pymongo==2.9.2
requests==2.9.1
gunicorn==19.3.0

我的包括:

import sys, os, re, hashlib, logging, urllib
import hashlib, base64, uuid, datetime, json, requests
from flask import Flask, request, redirect
from flask import render_template
from database import mongo
from random import shuffle
from datetime import timedelta

我可以现实地做些什么来阐明这个问题 - 我不知道哪个组件行为不端并导致问题。我怎样才能获得更清晰的更具体的错误消息?

1 个答案:

答案 0 :(得分:0)

最后,导致urlencode

的版本问题

它解决了:

try:
    from urllib.parse import urlencode
except ImportError:
    from urllib import urlencode

但是我只能在安装NewRelic之后发现这条消息 - 这实际上是一个非常棒的工具!