First off, I'm not sure if this is an issue with johnny-cache or gunicorn (or neither), and I've been able to work around it without much difficulty, but nonetheless I thought I'd report it here in case anyone else has the same trouble.
I followed the instructions in the JC docs and because my app makes extensive use of management commands and celery tasks, I needed to ensure that JC was enabled throughout, so I added the enable lines to my project's __init__.py
as directed:
from johnny.cache import enable
enable()
This however caused an error every time my gunicorn workers booted, with the stack trace seeming to indicate JC (or something) was being initialised "too early" in the process:
2013-03-09 06:11:51 [21016] [DEBUG] Exception in worker process:
Traceback (most recent call last):
File "/home/biggleszx/.virtualenvs/myappname/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in spawn_worker
worker.init_process()
File "/home/biggleszx/.virtualenvs/myappname/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 99, in init_process
self.wsgi = self.app.wsgi()
File "/home/biggleszx/.virtualenvs/myappname/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 101, in wsgi
self.callable = self.load()
File "/home/biggleszx/.virtualenvs/myappname/local/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 91, in load
return mod.make_wsgi_application()
File "/home/biggleszx/.virtualenvs/myappname/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 34, in make_wsgi_application
if get_validation_errors(s):
File "/home/biggleszx/.virtualenvs/myappname/local/lib/python2.7/site-packages/django/core/management/validation.py", line 28, in get_validation_errors
from django.db import models, connection
File "/home/biggleszx/.virtualenvs/myappname/local/lib/python2.7/site-packages/django/db/__init__.py", line 14, in <module>
if not settings.DATABASES:
File "/home/biggleszx/.virtualenvs/myappname/local/lib/python2.7/site-packages/django/utils/functional.py", line 276, in __getattr__
self._setup()
File "/home/biggleszx/.virtualenvs/myappname/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/home/biggleszx/.virtualenvs/myappname/local/lib/python2.7/site-packages/django/conf/__init__.py", line 89, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'myappname.config.live.settings' (Is it on sys.path?): cannot import name connections
Needless to say I checked and nothing in my app referred to this "connections" import, but I don't know if that's something specific to JC or gunicorn, or neither.
I tried moving the enable lines from __init__.py
into my main project settings.py
file and the same thing occurred.
Anyway, I was able to solve the issue by removing the enable lines and placing them within my management commands and celery task files, where everything seems to work just fine.
FYI, the relevant packages in my virtualenv look like this:
Django==1.3.1
gunicorn==0.14.5
johnny-cache==1.4
python-memcached==1.48
I'm using memcached version 1.4.14-0ubuntu1
on Ubuntu 12.10 64-bit. I note that the gunicorn version I'm using is now a little out of date (so's Django, for that matter), so I wonder if that might have something to do with it.
Anyway, hope this helps someone in a similar situation.