memcache error

43 views
Skip to first unread message

Scott

unread,
Jul 21, 2010, 8:27:53 AM7/21/10
to web2py-users
I'm running Ubuntu 10.04 and installed memcached which works fine
locally. I installed the web2py stable 1.84.1 build and the stable
wiki plugin from web2py.com. I followed the instructions at:
http://web2py.com/book/default/section/11/12 to store the sessions in
memcache for the provided Welcome app. Specifically, I created the
0_memcache.py model as instructed and I've tried adding the lines:

from gluon.contrib.memdb import MEMDB
session.connect(request,response,db=MEMDB(cache.memcache))

to either db.py or 0_memcache.py. In either case, when I load the
welcome app, the following ticket is generated:

Traceback (most recent call last):
File "/home/scott/Projects/web2py/gluon/main.py", line 391, in
wsgibase
session._try_store_in_db(request, response)
File "/home/scott/Projects/web2py/gluon/globals.py", line 361, in
_try_store_in_db
record_id = table.insert(**dd)
File "/home/scott/Projects/web2py/gluon/contrib/memdb.py", line 256,
in insert
id = self._create_id()
File "/home/scott/Projects/web2py/gluon/contrib/memdb.py", line 291,
in _create_id
id = self._tableobj.incr(shard_id)
File "/home/scott/Projects/web2py/gluon/contrib/memcache/
memcache.py", line 404, in incr
return self._incrdecr("incr", key, delta)
File "/home/scott/Projects/web2py/gluon/contrib/memcache/
memcache.py", line 428, in _incrdecr
return int(line)
ValueError: invalid literal for int() with base 10: 'NOT_FOUND'


Suggestions are welcome!

Scott

unread,
Jul 21, 2010, 8:36:57 AM7/21/10
to web2py-users
One other thing I've noted is that by setting this, attempting to
view /welcome/appadmin/ccache will generate the following ticket:

Traceback (most recent call last):
File "/home/scott/Projects/web2py/gluon/restricted.py", line 178, in
restricted
exec ccode in environment
File "/home/scott/Projects/web2py/applications/welcome/controllers/
appadmin.py", line 410, in <module>
File "/home/scott/Projects/web2py/gluon/globals.py", line 96, in
<lambda>
self._caller = lambda f: f()
File "/home/scott/Projects/web2py/applications/welcome/controllers/
appadmin.py", line 337, in ccache
for key, value in cache.ram.storage.items():
AttributeError: '_MemcacheClient' object has no attribute 'storage'

mdipierro

unread,
Jul 21, 2010, 8:43:33 AM7/21/10
to web2py-users
I do not remember who wrote that code but I just looked at it and I am
bit confused by it.
Anyway, I think I have a fix. Please try replace gluon/contribmemcache/
memcache.py with this file:

http://web2py.googlecode.com/hg/gluon/contrib/memcache/memcache.py

Massimo

On Jul 21, 7:27 am, Scott <blueseas...@gmail.com> wrote:
> I'm running Ubuntu 10.04 and installed memcached which works fine
> locally.  I installed the web2py stable 1.84.1 build and the stable
> wiki plugin from web2py.com.  I followed the instructions at:http://web2py.com/book/default/section/11/12to store the sessions in

Scott

unread,
Jul 21, 2010, 10:11:57 AM7/21/10
to web2py-users
Massimo,

That fixed the "
ValueError: invalid literal for int() with base 10: 'NOT_FOUND' "
error for missing sessions. Thanks!

The "
AttributeError: '_MemcacheClient' object has no attribute 'storage'"
error remains. Maybe the code block and imports from gluon/cache.py
need to be added to gluon/contrib/memcache/__init__.py?

if not app in self.meta_storage:
self.storage = self.meta_storage[app] =
{CacheAbstract.cache_stats_name: {
'hit_total': 0,
'misses': 0,
}}


On Jul 21, 8:43 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> I do not remember who wrote that code but I just looked at it and I am
> bit confused by it.
> Anyway, I think I have a fix. Please try replace gluon/contribmemcache/
> memcache.py with this file:
>
> http://web2py.googlecode.com/hg/gluon/contrib/memcache/memcache.py
>
> Massimo
>
> On Jul 21, 7:27 am, Scott <blueseas...@gmail.com> wrote:
>
> > I'm running Ubuntu 10.04 and installed memcached which works fine
> > locally.  I installed the web2py stable 1.84.1 build and the stable
> > wiki plugin from web2py.com.  I followed the instructions at:http://web2py.com/book/default/section/11/12tostore the sessions in

mdipierro

unread,
Jul 21, 2010, 10:53:37 AM7/21/10
to web2py-users
Please try trunk again and let me know.

On Jul 21, 9:11 am, Scott <blueseas...@gmail.com> wrote:
> Massimo,
>
> That fixed the "
> ValueError: invalid literal for int() with base 10: 'NOT_FOUND' "
> error for missing sessions.  Thanks!
>
> The "
> AttributeError: '_MemcacheClient' object has no attribute 'storage'"
> error remains.  Maybe the code block and imports from gluon/cache.py
> need to be added to gluon/contrib/memcache/__init__.py?
>
>         if not app in self.meta_storage:
>             self.storage = self.meta_storage[app] =
> {CacheAbstract.cache_stats_name: {
>                 'hit_total': 0,
>                 'misses': 0,
>             }}
>
> On Jul 21, 8:43 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > I do not remember who wrote that code but I just looked at it and I am
> > bit confused by it.
> > Anyway, I think I have a fix. Please try replace gluon/contribmemcache/
> > memcache.py with this file:
>
> >http://web2py.googlecode.com/hg/gluon/contrib/memcache/memcache.py
>
> > Massimo
>
> > On Jul 21, 7:27 am, Scott <blueseas...@gmail.com> wrote:
>
> > > I'm running Ubuntu 10.04 and installed memcached which works fine
> > > locally.  I installed the web2py stable 1.84.1 build and the stable
> > > wiki plugin from web2py.com.  I followed the instructions at:http://web2py.com/book/default/section/11/12tostorethe sessions in

Scott

unread,
Jul 21, 2010, 2:25:22 PM7/21/10
to web2py-users
OK, I got an error, unknown global variable 'app' in
gluon.contrib.memcache.__init__.py. Here are the proposed code fixes
to memcache.__init__.py which I've tested locally and know to work:

Add this import at the top of the file:
from gluon.cache import CacheAbstract

In class _MemcacheClient(Client):, def__init__..., directly below
"self.request=request" add:
if request:
app = request.application
else:
app = ''

Thanks for all your help Massimo! With these fixes, I think we have
the issue resolved. I will investigate adding Memcache stats to the
appadmin controller as a separate task.
> > > > wiki plugin from web2py.com.  I followed the instructions at:http://web2py.com/book/default/section/11/12tostorethesessions in

mdipierro

unread,
Jul 21, 2010, 4:31:42 PM7/21/10
to web2py-users
Please check trunk again. Thanks for your help.

Scott

unread,
Jul 21, 2010, 7:24:38 PM7/21/10
to web2py-users
Massimo,

I just checked out the trunk and I'm seeing an issue preventing the
loading of the Welcome app:

File "C:\Users\scott\Documents\workspace\web2py-dev\gluon\main.py",
line 384, in wsgibase
if static_file:
UnboundLocalError: local variable 'static_file' referenced before
assignment

I see static_file assigned a value on line 316 of main.py, but I think
you might want to give it a default value in case the assignment
fails, which is what appears to be happening.

--Scott

Scott

unread,
Jul 21, 2010, 8:20:26 PM7/21/10
to web2py-users
Massimo, please add the import:

from gluon.cache import CacheAbstract

to the top of gluon\contrib\memcache\__init__.py.

Thanks!
Reply all
Reply to author
Forward
0 new messages