python - 错误R10(引导超时) - > Web进程在启动后60秒内无法绑定到$ PORT

Adi*_*lik 7 python heroku python-2.7 python-3.x

我正在部署一个python脚本heroku,它将在每次之后向另一个服务器发出请求3 minutes.

部署进展顺利但是当我看到它时logs,我得到了这些errors.

2016-11-01T07:42:12.919755+00:00 heroku[web.1]: Starting process with command `python script.py --log-file -`
2016-11-01T07:43:13.097413+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-11-01T07:43:13.097556+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-11-01T07:43:13.196156+00:00 heroku[web.1]: Process exited with status 137
2016-11-01T07:43:13.212942+00:00 heroku[web.1]: State changed from starting to crashed
2016-11-01T07:43:13.213858+00:00 heroku[web.1]: State changed from crashed to starting
2016-11-01T07:43:16.719828+00:00 heroku[web.1]: Starting process with command `python script.py --log-file -`
2016-11-01T07:44:17.215381+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-11-01T07:44:17.215381+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-11-01T07:44:17.364708+00:00 heroku[web.1]: Process exited with status 137
2016-11-01T07:44:17.367610+00:00 heroku[web.1]: State changed from starting to crashed 
Run Code Online (Sandbox Code Playgroud)

Procfile

web: python script.py --log-file -
Run Code Online (Sandbox Code Playgroud)

script.py

import sys
import requests
from apscheduler.schedulers.blocking import BlockingScheduler

sched = BlockingScheduler()

@sched.scheduled_job('interval', minutes=3)
def timed_job():
    try:
        request = requests.get(url='https://royal-tag-services.herokuapp.com/api/sms-service/scheduler/')
    except Exception as e:
        print >>sys.stderr, 'scheduler request failed'

sched.start()
Run Code Online (Sandbox Code Playgroud)

Result of 'tree -L 1' command

??? Procfile
??? requirements.txt
??? script.py
??? supporterenv
Run Code Online (Sandbox Code Playgroud)

Yon*_*tch 16

在Procfile中将"web"替换为"worker".

  • 注意:您需要运行“heroku ps:scale worker=1”,因为工作线程不会自动缩放(并且您应该运行“heroku ps:scale web=0”来删除 Web cpu) (6认同)
  • 如果Procfile中具有“ Web”进程类型,则运行该进程的dyno必须在60秒内(默认情况下)绑定到其分配的$ PORT,以便能够通过http / s响应传入的Web请求。如果不是,则按照https://devcenter.heroku.com/articles/error-codes#r10-boot-timeout中的说明,Heroku取消了dyno。由于您的python脚本不是Web服务器,因此不应在Procfile中将其条目定义为“ Web”进程类型。 (2认同)