I have the following snippet in a Django view to render memcache stats:
import datetime, re, memcache
host = memcache._Host(settings.CACHES['default']['LOCATION'])
host.connect()
host.send_cmd("stats")
output = ''
while 1:
line = host.readline()
if line[0] == "END":
break
output += line + "\n"
host.close_socket()
return output
When I try this out, I get a timeout on the readline() statement.
Trying out this code via manage.py shell works fine, however.
It works in the view if I use this snippet instead:
p2 = subprocess.Popen(["echo \"stats\" | nc " + settings.CACHES['default']['LOCATION'].replace(':', ' ')], stdout = subprocess.PIPE, shell=True)
return p2.stdout.read()
I can just ignore the timeout for the previous code and use the subprocess method, but I’m really interested in knowing what could be wrong. Anyone ever run into this issue?
Nevermind, it should read:
end not: