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"
    }
}

 

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM