Cannot get the value from dogpile.cache from different modules.

Peter Otten __peter__ at web.de
Tue Dec 29 14:11:17 EST 2015


xeon Mailinglist wrote:

> No, I cannot get a simpler example. The simpler example works, and in my
> code, it doesn't. 

Then you have to add/remove complexity until you find the problematic 
statements.

> I thought that it was something related to the variable
> `region`, but I declare it as global. 

The "global" statement tells a function that a name in the module namespace 
should be used even though there is an assignment to that name inside the 
function. Example:

_value = 0

def next_int():
    global _value
    _value += 1
    return _value

It is unlikely that this feature will affect your problem.

> So, I think that all the sets will
> go to the same variable.

You can add print statements to your getters/setters

>>> from dogpile.cache import make_region
>>> region = make_region()
>>> region.configure("dogpile.cache.memory")
<dogpile.cache.region.CacheRegion object at 0x7f61f60cafd0>
>>> region.backend
<dogpile.cache.backends.memory.MemoryBackend object at 0x7f61f5e3e110>

to see if the object IDs are the same (I bet they aren't).

Another shot in the dark: an unobvious source of running code twice is when 
you import (directly or indirectly) the main script:

$ cat demo.py
import demo
print "demo"
$ python demo.py 
demo
demo





More information about the Python-list mailing list