对于flask应用

启动命令为 python app.py

 

使用gunicorn启动

pip install gunicorn

python gunicorn --workers=7 switch_app:app -b 0.0.0.0:6002

 

 

将gunicorn的配置参数写入文件 config.py

python gunicorn -c config.py switch_app:app

其中switch_app为文件名 switch_app.py  ,app为文件中的app对象

 

 

config.py的代码如下

import os 

import gevent.monkey

gevent.monkey.patch_all()

import multiprocessing

#debug = True

loglevel = 'debug'

bind = "0.0.0.0:6002"

pidfile = "logs/gunicorn.pid"

accesslog = "logs/access.log"

errorlog = "logs/debug.log"

daemon = True

timeout = 180

#启动进程数

workers=multiprocessing.cpu_count()

worker_class = 'gevent'

x_forwarded_for_header = 'X-FORWARDED-FOR'

 

 

其中timeout=180表示超过180秒未反应就关闭该请求响应,会得到请求被异常关闭的日志信息,默认超时时间为60秒左右

 posted on 2019-10-09 14:02  庭明  阅读(1313)  评论(0编辑  收藏  举报