django channel 常见报错

背景

项目投产前准备步骤

1.新建虚拟环境

2.安装nginx 配置wsgi

3.启动应用服务器(建议80/443)端口

4.配置web服务器

5.配置域名

 

 

django took too long to shut down and was killed 报错

症状:

项目可以正常启动,每次只能处理一个请求,启动的服务很容易卡死

 

attributeerror 'inmemorychannelayer' object has no attribute 'get'  报错

 

症状:

向数据库新增数据的时候提示 attributeerror 'inmemorychannelayer' object has no attribute 'get'

 

解决方案

运行环境

python3.7

pip==19.0.3  必须使用这个版本

django==3.1.3

channels==2.2.0 如果pip版本大于20的时候,安装channels会导致django 自动降级到2.1版本

channels-redis==2.3.3

 

settings.py 配置

redis 集群配置 

其它配置请参照官网:https://channels.readthedocs.io/en/stable/topics/channel_layers.html

CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': [
            "redis://127.0.0.1:6379/0",
            "redis://127.0.0.1:6380/0",
            "redis://127.0.0.1:6381/0",
        ],
        'OPTIONS': {
            'REDIS_CLIENT_CLASS': 'rediscluster.RedisCluster',
            'CONNECTION_POOL_CLASS': 'rediscluster.connection.ClusterConnectionPool',
            # 'CONNECTION_POOL_KWARGS': {
            #    'skip_full_coverage_check': True
            # }
        }
    }
}
CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels.layers.InMemoryChannelLayer"
    }
}

 

 

  

 

posted @ 2021-01-08 09:47  汪丛兴  阅读(1550)  评论(0编辑  收藏  举报