gunicorn使用模板

gunicorn使用模板

gunicorn使用拢共就两部:1,写好配置,2,启动。

1. gunicorn配置

​ 主要使用两种方式进行配置:1, command line ;2, configuration file。

​ 命令行的参数和配置文件的参数不一样,官方文档有一一对应的说明。https://docs.gunicorn.org/en/stable/settings.html

方式一:command line配置

gunicorn -D -w 4 -b 0.0.0.0:8000 my_service:app

好处是快速启动,缺点是参数一多,命令很长,难以阅读。

gunicorn -h # 查找所有配置参数,不一一赘述。
方式二:configuration file配置

是一个python文件:my_gunicorn.conf.py,使用方式:gunicorn -c my_gunicorn.conf.py app_test:app,app_test是自己的web接口.py文件。

模板如下:


import logging
import logging.handlers
from logging.handlers import WatchedFileHandler
import os
import multiprocessing
import gevent.monkey
# 全局变量
gevent.monkey.patch_all() # gevnet猴子补丁模块,实现多任务的方式。

BASE_DIR = os.path.abspath(os.path.dirname(__file__)) # 当前这个配置文件所在的上级文件夹的绝对路径。

chdir = BASE_DIR # gunicorn要切换到的目的工作目录

pidfile = os.path.join(BASE_DIR, './run/gunicorn.pid') # 设置进程文件目录(存储的是master进程的ID)



# 基本设置
debu = True # 当web接口发生变化时,重新加载,方便调试。

bind = '0.0.0.0:5000'  # 绑定ip和端口号

timeout = 30  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值