繁体   English   中英

Gunicorn 没有找到“memcache”模块,但是当我运行 python3 manage.py runserver 0.0.0.0:8000 时找到它

[英]Gunicorn isnt finding 'memcache' module but it is found when I run python3 manage.py runserver 0.0.0.0:8000

我的服务器有问题。 这是一个多租户项目,Windows 服务器中的项目工作正常,但 Ubuntu 中的项目虽然已安装,但给我一个“没有名为‘memcache’的模块”错误。 我知道它已安装,因为我运行了“python3 manage.py runserver 0.0.0.0:8001”,当我通过个人浏览器访问时工作正常。Gunicorn 正确指向我的虚拟环境,当我重新启动时没有日志错误服务,我现在很绝望。

我的配置:

CACHE_HOST = os.getenv('cache_host', '127.0.0.1')

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': f'{CACHE_HOST}:11211',
    },
    'estadisticos': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': f'{CACHE_HOST}:11211',
    }
}

那么您的 memcache 主机是否在 localhost 上运行? 如果不是,gunicorn 可能是作为服务启动的,并且没有正确的 env var cache_host

在任何情况下,我都建议您在设置文件的末尾添加打印并打印一个以查看您是否对 gunicorn 和命令行使用相同的 ptyhon:

import sys  # if not already imported in settings
print("my python is ", sys.executable)
print("CACHES", CACHES, file=sys.stderr)

或者如果您看不到 stdout: with open("/tmp/mylog.log") as fout: print("my python is ", sys.executable, file=fout) print("CACHES", CACHES, file= f)


Check that python3 manage.py runserver 0.0.0.0:8001 creates the same trace as running gunicorn.
delete the file `/tmp/mylog.log` between the two runs.

如果输出相同,但 memcached 对其中一个有效,而对另一个无效,则必须检查 django 设置是否未在其他地方覆盖

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM