memcached occasional errors

154 views
Skip to first unread message

het.oosten

unread,
Jul 26, 2011, 2:29:18 AM7/26/11
to Django users
On the memcached mailing list they suspected this is a Django/python
issue so I started a thread here. A user named dormando replied that
the problem below looks like a connection failure (sock has gone null)

I use memcached on a low traffic website with Django 1.2.4. Sometimes
I get this error message in my mail (full error below):

AttributeError: 'NoneType' object has no attribute 'recv'

I use memcache to cache some Twitter messages. I fetch them using this
in a context-preprocessor:
def latest_tweet( request ):
tweet = cache.get( 'tweet_mysite_nl' )

if tweet:
return {"tweet": tweet}
else:
tweet = {}
return {"tweet": tweet}

I tried to trigger this error hitting refresh all the time, but with
my pc everything works fine.

I update the cache twice an hour with another view, using cron
(because I don't want to rely on an external site for performance):

def update_tweet(request):
import time
from django.conf import settings
from django.core.cache import cache
import twitter
tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER,
count=5 )
for s in tweet:
s.date =
datetime.datetime(*(time.strptime( s.created_at, "%a %$
cache.set( 'tweet_mysite_nl', tweet,
settings.TWITTER_TIMEOUT )
return HttpResponseRedirect('mysite')

Here is the full error message:

Traceback (most recent call last):

File "/usr/lib/python2.4/site-packages/django/core/handlers/
base.py", line 100, in get_response
response = callback(request, *callback_args, **callback_kwargs)

File "/usr/lib/python2.4/site-packages/django/views/generic/
simple.py", line 16, in direct_to_template
c = RequestContext(request, dictionary)

File "/usr/lib/python2.4/site-packages/django/template/context.py",
line 149, in __init__
self.update(processor(request))

File "/home/wieskamp/django/wieskamp/verkoop/context_processors.py",
line 8, in latest_tweet
tweet = cache.get( 'tweet_mysite_nl' )

File "/usr/lib/python2.4/site-packages/django/core/cache/backends/
memcached.py", line 48, in get
val = self._cache.get(smart_str(key))

File "/usr/lib/python2.4/site-packages/memcache.py", line 337, in
get
rkey, flags, rlen, = self._expectvalue(server)

File "/usr/lib/python2.4/site-packages/memcache.py", line 411, in
_expectvalue
line = server.readline()

File "/usr/lib/python2.4/site-packages/memcache.py", line 511, in
readline
recv = self.socket.recv

AttributeError: 'NoneType' object has no attribute 'recv'

Russell Keith-Magee

unread,
Jul 26, 2011, 3:32:19 AM7/26/11
to django...@googlegroups.com
On Tue, Jul 26, 2011 at 2:29 PM, het.oosten <het.o...@gmail.com> wrote:
> On the memcached mailing list they suspected this is a Django/python
> issue so I started a thread here. A user named dormando replied that
> the problem below looks like a connection failure (sock has gone null)
>
>  I use memcached on a low traffic website with Django 1.2.4. Sometimes
> I get this error message in my mail (full error below):

This looks like it's more likely to be an issue with the Python
wrapper to memcache that you are using, rather than an issue with
Django. Although the stack trace occurs as a result of Django calling
the memcache API, the call is a simple get, and it's the internals of
memcache.py that are failing. Django doesn't do any socket-level
manipulation of memcache, and that appears to be where the problem
lies.

It looks like you're using the native Python wrapper around memcached;
is this correct? If so, what version of the Python memcache library
are you using? Have you tried updating to the latest version? Have you
tried using PyLibMC instead?

Yours,
Russ Magee %-)

Henrik Genssen

unread,
Jul 26, 2011, 3:57:39 AM7/26/11
to django...@googlegroups.com
PyLibMC was introduced in django 1.3 and he is using 1.2
you need to upgrade to upgrade django to use that lib - or am I wrong?

>reply to message:
>date: 26.07.2011 09:32:19
>from: "Russell Keith-Magee" <rus...@keith-magee.com>
>to: django...@googlegroups.com
>subject: [<django-users.googlegroups.com>] Re: memcached occasional errors

>--
>You received this message because you are subscribed to the Google Groups "Django users" group.
>To post to this group, send email to django...@googlegroups.com.
>To unsubscribe from this group, send email to django-users...@googlegroups.com.
>For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>

het.oosten

unread,
Jul 26, 2011, 5:42:17 AM7/26/11
to Django users
Thanks for the replies. I installed python-memcached through the
package manager. This version was outdated. I updated python-memcached
to the latest version now (1.47)

When I keep getting these error messages I will look into PyLibMC.
Anybody have any experience with PyLibMC and Django 1.2.4?

Rob
Reply all
Reply to author
Forward
0 new messages