Gunicorn 未找到 'memcache' 模块,但在我 运行 python3 manage.py 运行server 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 中的那个虽然安装了但给我一个 "No module named 'memcache'" 错误。我知道它已安装,因为我 运行 a "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',
}
}
那么您的内存缓存主机 运行 在本地主机上吗?如果不是,也许 gunicorn 是作为服务启动的,并且没有正确的环境变量值 cache_host
无论如何,我建议您在设置文件的末尾添加打印件
并打印一张以查看您是否对 gunicorn 和命令行使用相同的 ptyhon:
import sys # if not already imported in settings
print("my python is ", sys.executable)
print("CACHES", CACHES, file=sys.stderr)
或者如果您看不到标准输出:
以 open("/tmp/mylog.log") 作为 fout:
打印("my python is ",sys.executable,文件=fout)
打印("CACHES",缓存,文件=fout)
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 设置没有在其他地方被覆盖
我的服务器出现问题。这是一个多租户项目,Windows 服务器中的那个工作正常,但是 Ubuntu 中的那个虽然安装了但给我一个 "No module named 'memcache'" 错误。我知道它已安装,因为我 运行 a "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',
}
}
那么您的内存缓存主机 运行 在本地主机上吗?如果不是,也许 gunicorn 是作为服务启动的,并且没有正确的环境变量值 cache_host
无论如何,我建议您在设置文件的末尾添加打印件 并打印一张以查看您是否对 gunicorn 和命令行使用相同的 ptyhon:
import sys # if not already imported in settings
print("my python is ", sys.executable)
print("CACHES", CACHES, file=sys.stderr)
或者如果您看不到标准输出: 以 open("/tmp/mylog.log") 作为 fout: 打印("my python is ",sys.executable,文件=fout) 打印("CACHES",缓存,文件=fout)
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 设置没有在其他地方被覆盖