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

xeon Mailinglist xeonmailinglist at gmail.com
Tue Dec 29 12:38:06 EST 2015


On Tuesday, December 29, 2015 at 5:33:43 PM UTC, Peter Otten wrote:
> xeon Mailinglist wrote:
>> > On Tuesday, December 29, 2015 at 4:18:10 PM UTC, Peter Otten wrote:
> >> xeon Mailinglist wrote:
> >> 
> >> > On Tuesday, December 29, 2015 at 11:16:10 AM UTC, xeon Mailinglist
> >> > wrote:
> >> >> 1. How do I create a global variable that can be accessed by all
> >> >> classes?
> >> >> 
> >> >> 2. I am using `dogpile.cache` to store data in the cache [1], but if I
> >> >> set and get the same key from different modules, I don't get the
> >> >> value. Here is an example in [2]. The value than I get is
> >> >> `NO_VALUE.NO_VALUE`. Why this happens?
> >> 
> >> >> region = make_region().configure('dogpile.cache.memory')
> >> 
> >> The memory backend wraps a python dict whose contents are only available
> >> to a single script and forgotten when that script ends.
> >> 
> >> My crystal ball tells me that you want to communicate between processes
> >> rather than "modules" and need a backend that implements persistence.
> >> "dogpile.cache.file" seems to be the one without dependencies outside the
> >> standard library.
> > 
> > 
> > No. 
>> Does "No" mean "I have run my code with another backend, and the modified 
> script showed the same behaviour"?
>> > My problem is that I have method1() that calls method2() which calls
> > myset(). method1() -> method2() -> myset(5). My problem is that, if I try
> > to get the value of myset() inside method1(), I can't have it. It seems
> > that the program has lost the value.
>> I can't make sense of that. You should be able to nest methods to your 
> heart's content (as long as you don't reach the recursion limit).
>> Can you post minimal versions of your modules in such a way that I can 
> easily run them over here? 
>> If you have only one process you probably have somehow managed to get two 
> backend dicts. Unfortunately there's a blind spot on my crystal ball, and I 
> can't see how exactly you did it...

No, I cannot get a simpler example. The simpler example works, and in my code, it doesn't. I thought that it was something related to the variable `region`, but I declare it as global. So, I think that all the sets will go to the same variable.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /