Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100948 > unrolled thread

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

Started byxeon Mailinglist <xeonmailinglist@gmail.com>
First post2015-12-29 03:15 -0800
Last post2015-12-29 17:49 -0500
Articles 15 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 03:15 -0800
    Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 07:20 -0800
      Re: Cannot get the value from dogpile.cache from different modules. Peter Otten <__peter__@web.de> - 2015-12-29 17:17 +0100
        Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 09:13 -0800
          Re: Cannot get the value from dogpile.cache from different modules. Peter Otten <__peter__@web.de> - 2015-12-29 18:33 +0100
            Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 09:38 -0800
              Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 10:22 -0800
              Re: Cannot get the value from dogpile.cache from different modules. Peter Otten <__peter__@web.de> - 2015-12-29 20:11 +0100
      Re: Cannot get the value from dogpile.cache from different modules. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-29 17:14 +0000
        Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 09:23 -0800
        Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 09:27 -0800
          Re: Cannot get the value from dogpile.cache from different modules. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-29 19:22 +0000
            Re: Cannot get the value from dogpile.cache from different modules. xeon Mailinglist <xeonmailinglist@gmail.com> - 2015-12-29 14:57 -0800
              Re: Cannot get the value from dogpile.cache from different modules. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-29 23:30 +0000
          Re: Cannot get the value from dogpile.cache from different modules. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-12-29 17:49 -0500

#100948 — Cannot get the value from dogpile.cache from different modules.

Fromxeon Mailinglist <xeonmailinglist@gmail.com>
Date2015-12-29 03:15 -0800
SubjectCannot get the value from dogpile.cache from different modules.
Message-ID<7c8df879-b03a-4323-90c5-3221dd1eced2@googlegroups.com>
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?

setter is the setter.py
getter is the getter.py
Memoize is the file in [1].


[1] my dogpile class `Memoize.py`

    from dogpile.cache import make_region

    region = make_region().configure('dogpile.cache.memory')

    def save(key, value):
      """
      general purpose method to save data (value) in the cache
    
      :param key (string) key of the value to be saved in cache
      :param value (any type) the value to be saved
      """
      region.set(key, value)


    def get(key):
      """
      general purpose method to get data from the cache
 
      :param key (string) key of the data to be fetched
      :return value (any type) data to be returned from the cache
      """
      return region.get(key)


[2] My python example

`setter.py`

    def myset(value):     
      Memoize.save("myvalue", value)

`getter.py`

   def myget():
      return Memoize.get("myvalue") <- this value is NO_VALUE. NO_VALUE

My class:

    setter.myset(123)
    getter.myget()

   

[toc] | [next] | [standalone]


#100957

Fromxeon Mailinglist <xeonmailinglist@gmail.com>
Date2015-12-29 07:20 -0800
Message-ID<e94e9346-cccd-44cb-b889-75c308921555@googlegroups.com>
In reply to#100948
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?
> 
> setter is the setter.py
> getter is the getter.py
> Memoize is the file in [1].
> 
> 
> [1] my dogpile class `Memoize.py`
> 
>     from dogpile.cache import make_region
> 
>     region = make_region().configure('dogpile.cache.memory')
> 
>     def save(key, value):
>       """
>       general purpose method to save data (value) in the cache
>     
>       :param key (string) key of the value to be saved in cache
>       :param value (any type) the value to be saved
>       """
>       region.set(key, value)
> 
> 
>     def get(key):
>       """
>       general purpose method to get data from the cache
>  
>       :param key (string) key of the data to be fetched
>       :return value (any type) data to be returned from the cache
>       """
>       return region.get(key)
> 
> 
> [2] My python example
> 
> `setter.py`
> 
>     def myset(value):     
>       Memoize.save("myvalue", value)
> 
> `getter.py`
> 
>    def myget():
>       return Memoize.get("myvalue") <- this value is NO_VALUE. NO_VALUE
> 
> My class:
> 
>     setter.myset(123)
>     getter.myget()

The idea that I get from dogpile, is that in each module (getter.py, or setter.py) there is a dictionary where the values are stored in the backend. Hence, getter.py has its dictionary and setter.py has its dictionary also. In the end, there is not a single dictionary where all the values should be put. And I want a single dictionary.

[toc] | [prev] | [next] | [standalone]


#100958

FromPeter Otten <__peter__@web.de>
Date2015-12-29 17:17 +0100
Message-ID<mailman.54.1451405867.11925.python-list@python.org>
In reply to#100957
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.


[toc] | [prev] | [next] | [standalone]


#100959

Fromxeon Mailinglist <xeonmailinglist@gmail.com>
Date2015-12-29 09:13 -0800
Message-ID<10871dc8-ee11-41d8-ad3c-c0aab267be64@googlegroups.com>
In reply to#100958
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. 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.

[toc] | [prev] | [next] | [standalone]


#100963

FromPeter Otten <__peter__@web.de>
Date2015-12-29 18:33 +0100
Message-ID<mailman.56.1451410408.11925.python-list@python.org>
In reply to#100959
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...

[toc] | [prev] | [next] | [standalone]


#100964

Fromxeon Mailinglist <xeonmailinglist@gmail.com>
Date2015-12-29 09:38 -0800
Message-ID<8c87a009-57f7-45c6-bbf8-5c51411758e1@googlegroups.com>
In reply to#100963
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.

[toc] | [prev] | [next] | [standalone]


#100966

Fromxeon Mailinglist <xeonmailinglist@gmail.com>
Date2015-12-29 10:22 -0800
Message-ID<57353bd4-e089-4cbf-9551-4aed24849c3b@googlegroups.com>
In reply to#100964
On Tuesday, December 29, 2015 at 5:38:17 PM UTC, xeon Mailinglist wrote:
> 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.

Strangely enough, when I put the set values in the method1(), it works ok. Is it because method2() is in a submodule of method1?

[toc] | [prev] | [next] | [standalone]


#100968

FromPeter Otten <__peter__@web.de>
Date2015-12-29 20:11 +0100
Message-ID<mailman.58.1451416286.11925.python-list@python.org>
In reply to#100964
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

[toc] | [prev] | [next] | [standalone]


#100960

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-12-29 17:14 +0000
Message-ID<mailman.55.1451409296.11925.python-list@python.org>
In reply to#100957
On 29/12/2015 15:20, 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?
>>
>> setter is the setter.py
>> getter is the getter.py
>> Memoize is the file in [1].
>>
>>
>> [1] my dogpile class `Memoize.py`
>>
>>      from dogpile.cache import make_region
>>
>>      region = make_region().configure('dogpile.cache.memory')
>>
>>      def save(key, value):
>>        """
>>        general purpose method to save data (value) in the cache
>>
>>        :param key (string) key of the value to be saved in cache
>>        :param value (any type) the value to be saved
>>        """
>>        region.set(key, value)
>>
>>
>>      def get(key):
>>        """
>>        general purpose method to get data from the cache
>>
>>        :param key (string) key of the data to be fetched
>>        :return value (any type) data to be returned from the cache
>>        """
>>        return region.get(key)
>>
>>
>> [2] My python example
>>
>> `setter.py`
>>
>>      def myset(value):
>>        Memoize.save("myvalue", value)
>>
>> `getter.py`
>>
>>     def myget():
>>        return Memoize.get("myvalue") <- this value is NO_VALUE. NO_VALUE
>>
>> My class:
>>
>>      setter.myset(123)
>>      getter.myget()
>
> The idea that I get from dogpile, is that in each module (getter.py, or setter.py) there is a dictionary where the values are stored in the backend. Hence, getter.py has its dictionary and setter.py has its dictionary also. In the end, there is not a single dictionary where all the values should be put. And I want a single dictionary.
>

Then put everything in one file.  Three files for the amount of code you 
show above is nonsensical.  You might like to read 
http://dirtsimple.org/2004/12/python-is-not-java.html and in response to 
that http://dirtsimple.org/2004/12/java-is-not-python-either.html

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#100961

Fromxeon Mailinglist <xeonmailinglist@gmail.com>
Date2015-12-29 09:23 -0800
Message-ID<eca346d3-b105-4f44-ad76-382ee2036b70@googlegroups.com>
In reply to#100960
On Tuesday, December 29, 2015 at 5:15:24 PM UTC, Mark Lawrence wrote:
> On 29/12/2015 15:20, 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?
> >>
> >> setter is the setter.py
> >> getter is the getter.py
> >> Memoize is the file in [1].
> >>
> >>
> >> [1] my dogpile class `Memoize.py`
> >>
> >>      from dogpile.cache import make_region
> >>
> >>      region = make_region().configure('dogpile.cache.memory')
> >>
> >>      def save(key, value):
> >>        """
> >>        general purpose method to save data (value) in the cache
> >>
> >>        :param key (string) key of the value to be saved in cache
> >>        :param value (any type) the value to be saved
> >>        """
> >>        region.set(key, value)
> >>
> >>
> >>      def get(key):
> >>        """
> >>        general purpose method to get data from the cache
> >>
> >>        :param key (string) key of the data to be fetched
> >>        :return value (any type) data to be returned from the cache
> >>        """
> >>        return region.get(key)
> >>
> >>
> >> [2] My python example
> >>
> >> `setter.py`
> >>
> >>      def myset(value):
> >>        Memoize.save("myvalue", value)
> >>
> >> `getter.py`
> >>
> >>     def myget():
> >>        return Memoize.get("myvalue") <- this value is NO_VALUE. NO_VALUE
> >>
> >> My class:
> >>
> >>      setter.myset(123)
> >>      getter.myget()
> >
> > The idea that I get from dogpile, is that in each module (getter.py, or setter.py) there is a dictionary where the values are stored in the backend. Hence, getter.py has its dictionary and setter.py has its dictionary also. In the end, there is not a single dictionary where all the values should be put. And I want a single dictionary.
> >
> 
> Then put everything in one file.  Three files for the amount of code you 
> show above is nonsensical.  You might like to read 
> http://dirtsimple.org/2004/12/python-is-not-java.html and in response to 
> that http://dirtsimple.org/2004/12/java-is-not-python-either.html
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

No, that's not the answer. This is just an example. I will not give you the full code because it doesn't make any sense... I am trying to explain what is my problem, even though I cannot reproduce it in any simple example.

I save several keys with the dogpile and everything is ok, but when I try to save that particular value, it seems that is going to store in a new dictionary, and not in the dictionary with all the values.

[toc] | [prev] | [next] | [standalone]


#100962

Fromxeon Mailinglist <xeonmailinglist@gmail.com>
Date2015-12-29 09:27 -0800
Message-ID<337dc80d-bd55-4976-a716-fc8f793a1322@googlegroups.com>
In reply to#100960
On Tuesday, December 29, 2015 at 5:15:24 PM UTC, Mark Lawrence wrote:
> On 29/12/2015 15:20, 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?
> >>
> >> setter is the setter.py
> >> getter is the getter.py
> >> Memoize is the file in [1].
> >>
> >>
> >> [1] my dogpile class `Memoize.py`
> >>
> >>      from dogpile.cache import make_region
> >>
> >>      region = make_region().configure('dogpile.cache.memory')
> >>
> >>      def save(key, value):
> >>        """
> >>        general purpose method to save data (value) in the cache
> >>
> >>        :param key (string) key of the value to be saved in cache
> >>        :param value (any type) the value to be saved
> >>        """
> >>        region.set(key, value)
> >>
> >>
> >>      def get(key):
> >>        """
> >>        general purpose method to get data from the cache
> >>
> >>        :param key (string) key of the data to be fetched
> >>        :return value (any type) data to be returned from the cache
> >>        """
> >>        return region.get(key)
> >>
> >>
> >> [2] My python example
> >>
> >> `setter.py`
> >>
> >>      def myset(value):
> >>        Memoize.save("myvalue", value)
> >>
> >> `getter.py`
> >>
> >>     def myget():
> >>        return Memoize.get("myvalue") <- this value is NO_VALUE. NO_VALUE
> >>
> >> My class:
> >>
> >>      setter.myset(123)
> >>      getter.myget()
> >
> > The idea that I get from dogpile, is that in each module (getter.py, or setter.py) there is a dictionary where the values are stored in the backend. Hence, getter.py has its dictionary and setter.py has its dictionary also. In the end, there is not a single dictionary where all the values should be put. And I want a single dictionary.
> >
> 
> Then put everything in one file.  Three files for the amount of code you 
> show above is nonsensical.  You might like to read 
> http://dirtsimple.org/2004/12/python-is-not-java.html and in response to 
> that http://dirtsimple.org/2004/12/java-is-not-python-either.html
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Here is the full class that I use to store the data.

from dogpile.cache import make_region


# my_dictionary = {}
region = make_region().configure('dogpile.cache.memory')
# arguments={"cache_dict":my_dictionary})
class Cache:

    @staticmethod
    def save(key, value):
        """
        general purpose method to save data (value) in the cache

        :param key (string) key of the value to be saved in cache
        :param value (any type) the value to be saved
        """
        region.set(key, value)

    @staticmethod
    def get(key):
        """
        general purpose method to get data from the cache

        :param key (string) key of the data to be fetched
        :return value (any type) data to be returned from the cache
        """
        return region.get(key)


    @staticmethod
    def get_or_create(key):
        """
        General purpose method to get data from the cache. If the value does not exist, it creates a list

        :param: key (string) key of the data to be fetched
        :return value (any type) data to be returned from the cache
        """
        return region.get_or_create(key, list)

    @staticmethod
    def set_job_predictions(rank_list):
        Cache.save("job_predictions", rank_list)

    @staticmethod
    def get_job_predictions():
        return Cache.get("job_predictions")

[toc] | [prev] | [next] | [standalone]


#100969

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-12-29 19:22 +0000
Message-ID<mailman.59.1451417000.11925.python-list@python.org>
In reply to#100962
On 29/12/2015 17:27, xeon Mailinglist wrote:
> On Tuesday, December 29, 2015 at 5:15:24 PM UTC, Mark Lawrence wrote:
>> On 29/12/2015 15:20, 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?
>>>>
>>>> setter is the setter.py
>>>> getter is the getter.py
>>>> Memoize is the file in [1].
>>>>
>>>>
>>>> [1] my dogpile class `Memoize.py`
>>>>
>>>>       from dogpile.cache import make_region
>>>>
>>>>       region = make_region().configure('dogpile.cache.memory')
>>>>
>>>>       def save(key, value):
>>>>         """
>>>>         general purpose method to save data (value) in the cache
>>>>
>>>>         :param key (string) key of the value to be saved in cache
>>>>         :param value (any type) the value to be saved
>>>>         """
>>>>         region.set(key, value)
>>>>
>>>>
>>>>       def get(key):
>>>>         """
>>>>         general purpose method to get data from the cache
>>>>
>>>>         :param key (string) key of the data to be fetched
>>>>         :return value (any type) data to be returned from the cache
>>>>         """
>>>>         return region.get(key)
>>>>
>>>>
>>>> [2] My python example
>>>>
>>>> `setter.py`
>>>>
>>>>       def myset(value):
>>>>         Memoize.save("myvalue", value)
>>>>
>>>> `getter.py`
>>>>
>>>>      def myget():
>>>>         return Memoize.get("myvalue") <- this value is NO_VALUE. NO_VALUE
>>>>
>>>> My class:
>>>>
>>>>       setter.myset(123)
>>>>       getter.myget()
>>>
>>> The idea that I get from dogpile, is that in each module (getter.py, or setter.py) there is a dictionary where the values are stored in the backend. Hence, getter.py has its dictionary and setter.py has its dictionary also. In the end, there is not a single dictionary where all the values should be put. And I want a single dictionary.
>>>
>>
>> Then put everything in one file.  Three files for the amount of code you
>> show above is nonsensical.  You might like to read
>> http://dirtsimple.org/2004/12/python-is-not-java.html and in response to
>> that http://dirtsimple.org/2004/12/java-is-not-python-either.html
>>
>> --
>> My fellow Pythonistas, ask not what our language can do for you, ask
>> what you can do for our language.
>>
>> Mark Lawrence
>
> Here is the full class that I use to store the data.
>
> from dogpile.cache import make_region
>
>
> # my_dictionary = {}
> region = make_region().configure('dogpile.cache.memory')
> # arguments={"cache_dict":my_dictionary})
> class Cache:
>
>      @staticmethod
>      def save(key, value):
>          """
>          general purpose method to save data (value) in the cache
>
>          :param key (string) key of the value to be saved in cache
>          :param value (any type) the value to be saved
>          """
>          region.set(key, value)
>
>      @staticmethod
>      def get(key):
>          """
>          general purpose method to get data from the cache
>
>          :param key (string) key of the data to be fetched
>          :return value (any type) data to be returned from the cache
>          """
>          return region.get(key)
>
>
>      @staticmethod
>      def get_or_create(key):
>          """
>          General purpose method to get data from the cache. If the value does not exist, it creates a list
>
>          :param: key (string) key of the data to be fetched
>          :return value (any type) data to be returned from the cache
>          """
>          return region.get_or_create(key, list)
>
>      @staticmethod
>      def set_job_predictions(rank_list):
>          Cache.save("job_predictions", rank_list)
>
>      @staticmethod
>      def get_job_predictions():
>          return Cache.get("job_predictions")
>

I get the strong impression that you're reinventing wheels and doing it 
so badly that they're triangular.  Have you tried pypi 
https://pypi.python.org/pypi for proven code that could do the job for you?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#100974

Fromxeon Mailinglist <xeonmailinglist@gmail.com>
Date2015-12-29 14:57 -0800
Message-ID<f2a9b5d5-d848-49e8-b5c0-58cfc808f4b0@googlegroups.com>
In reply to#100969
On Tuesday, December 29, 2015 at 7:23:40 PM UTC, Mark Lawrence wrote:
> On 29/12/2015 17:27, xeon Mailinglist wrote:
> > On Tuesday, December 29, 2015 at 5:15:24 PM UTC, Mark Lawrence wrote:
> >> On 29/12/2015 15:20, 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?
> >>>>
> >>>> setter is the setter.py
> >>>> getter is the getter.py
> >>>> Memoize is the file in [1].
> >>>>
> >>>>
> >>>> [1] my dogpile class `Memoize.py`
> >>>>
> >>>>       from dogpile.cache import make_region
> >>>>
> >>>>       region = make_region().configure('dogpile.cache.memory')
> >>>>
> >>>>       def save(key, value):
> >>>>         """
> >>>>         general purpose method to save data (value) in the cache
> >>>>
> >>>>         :param key (string) key of the value to be saved in cache
> >>>>         :param value (any type) the value to be saved
> >>>>         """
> >>>>         region.set(key, value)
> >>>>
> >>>>
> >>>>       def get(key):
> >>>>         """
> >>>>         general purpose method to get data from the cache
> >>>>
> >>>>         :param key (string) key of the data to be fetched
> >>>>         :return value (any type) data to be returned from the cache
> >>>>         """
> >>>>         return region.get(key)
> >>>>
> >>>>
> >>>> [2] My python example
> >>>>
> >>>> `setter.py`
> >>>>
> >>>>       def myset(value):
> >>>>         Memoize.save("myvalue", value)
> >>>>
> >>>> `getter.py`
> >>>>
> >>>>      def myget():
> >>>>         return Memoize.get("myvalue") <- this value is NO_VALUE. NO_VALUE
> >>>>
> >>>> My class:
> >>>>
> >>>>       setter.myset(123)
> >>>>       getter.myget()
> >>>
> >>> The idea that I get from dogpile, is that in each module (getter.py, or setter.py) there is a dictionary where the values are stored in the backend. Hence, getter.py has its dictionary and setter.py has its dictionary also. In the end, there is not a single dictionary where all the values should be put. And I want a single dictionary.
> >>>
> >>
> >> Then put everything in one file.  Three files for the amount of code you
> >> show above is nonsensical.  You might like to read
> >> http://dirtsimple.org/2004/12/python-is-not-java.html and in response to
> >> that http://dirtsimple.org/2004/12/java-is-not-python-either.html
> >>
> >> --
> >> My fellow Pythonistas, ask not what our language can do for you, ask
> >> what you can do for our language.
> >>
> >> Mark Lawrence
> >
> > Here is the full class that I use to store the data.
> >
> > from dogpile.cache import make_region
> >
> >
> > # my_dictionary = {}
> > region = make_region().configure('dogpile.cache.memory')
> > # arguments={"cache_dict":my_dictionary})
> > class Cache:
> >
> >      @staticmethod
> >      def save(key, value):
> >          """
> >          general purpose method to save data (value) in the cache
> >
> >          :param key (string) key of the value to be saved in cache
> >          :param value (any type) the value to be saved
> >          """
> >          region.set(key, value)
> >
> >      @staticmethod
> >      def get(key):
> >          """
> >          general purpose method to get data from the cache
> >
> >          :param key (string) key of the data to be fetched
> >          :return value (any type) data to be returned from the cache
> >          """
> >          return region.get(key)
> >
> >
> >      @staticmethod
> >      def get_or_create(key):
> >          """
> >          General purpose method to get data from the cache. If the value does not exist, it creates a list
> >
> >          :param: key (string) key of the data to be fetched
> >          :return value (any type) data to be returned from the cache
> >          """
> >          return region.get_or_create(key, list)
> >
> >      @staticmethod
> >      def set_job_predictions(rank_list):
> >          Cache.save("job_predictions", rank_list)
> >
> >      @staticmethod
> >      def get_job_predictions():
> >          return Cache.get("job_predictions")
> >
> 
> I get the strong impression that you're reinventing wheels and doing it 
> so badly that they're triangular.  Have you tried pypi 
> https://pypi.python.org/pypi for proven code that could do the job for you?
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

@Mark
I don't understand your remark. Pypi is a repository. What this has to do with my problem?

@Peter
I have solve the problem, although it is a little bit unclear to me what is the reason. I start to think that this is a problem related to packages and sub-packages. Eg. method1() is in the mypkg/file1.py, and method2() is in mypkg/scheduler/file2.py.

[toc] | [prev] | [next] | [standalone]


#100976

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-12-29 23:30 +0000
Message-ID<mailman.63.1451431870.11925.python-list@python.org>
In reply to#100974
On 29/12/2015 22:57, xeon Mailinglist wrote:
> On Tuesday, December 29, 2015 at 7:23:40 PM UTC, Mark Lawrence wrote:
>> On 29/12/2015 17:27, xeon Mailinglist wrote:
>>> On Tuesday, December 29, 2015 at 5:15:24 PM UTC, Mark Lawrence wrote:
>>>> On 29/12/2015 15:20, 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?
>>>>>>
>>>>>> setter is the setter.py
>>>>>> getter is the getter.py
>>>>>> Memoize is the file in [1].
>>>>>>
>>>>>>
>>>>>> [1] my dogpile class `Memoize.py`
>>>>>>
>>>>>>        from dogpile.cache import make_region
>>>>>>
>>>>>>        region = make_region().configure('dogpile.cache.memory')
>>>>>>
>>>>>>        def save(key, value):
>>>>>>          """
>>>>>>          general purpose method to save data (value) in the cache
>>>>>>
>>>>>>          :param key (string) key of the value to be saved in cache
>>>>>>          :param value (any type) the value to be saved
>>>>>>          """
>>>>>>          region.set(key, value)
>>>>>>
>>>>>>
>>>>>>        def get(key):
>>>>>>          """
>>>>>>          general purpose method to get data from the cache
>>>>>>
>>>>>>          :param key (string) key of the data to be fetched
>>>>>>          :return value (any type) data to be returned from the cache
>>>>>>          """
>>>>>>          return region.get(key)
>>>>>>
>>>>>>
>>>>>> [2] My python example
>>>>>>
>>>>>> `setter.py`
>>>>>>
>>>>>>        def myset(value):
>>>>>>          Memoize.save("myvalue", value)
>>>>>>
>>>>>> `getter.py`
>>>>>>
>>>>>>       def myget():
>>>>>>          return Memoize.get("myvalue") <- this value is NO_VALUE. NO_VALUE
>>>>>>
>>>>>> My class:
>>>>>>
>>>>>>        setter.myset(123)
>>>>>>        getter.myget()
>>>>>
>>>>> The idea that I get from dogpile, is that in each module (getter.py, or setter.py) there is a dictionary where the values are stored in the backend. Hence, getter.py has its dictionary and setter.py has its dictionary also. In the end, there is not a single dictionary where all the values should be put. And I want a single dictionary.
>>>>>
>>>>
>>>> Then put everything in one file.  Three files for the amount of code you
>>>> show above is nonsensical.  You might like to read
>>>> http://dirtsimple.org/2004/12/python-is-not-java.html and in response to
>>>> that http://dirtsimple.org/2004/12/java-is-not-python-either.html
>>>>
>>>> --
>>>> My fellow Pythonistas, ask not what our language can do for you, ask
>>>> what you can do for our language.
>>>>
>>>> Mark Lawrence
>>>
>>> Here is the full class that I use to store the data.
>>>
>>> from dogpile.cache import make_region
>>>
>>>
>>> # my_dictionary = {}
>>> region = make_region().configure('dogpile.cache.memory')
>>> # arguments={"cache_dict":my_dictionary})
>>> class Cache:
>>>
>>>       @staticmethod
>>>       def save(key, value):
>>>           """
>>>           general purpose method to save data (value) in the cache
>>>
>>>           :param key (string) key of the value to be saved in cache
>>>           :param value (any type) the value to be saved
>>>           """
>>>           region.set(key, value)
>>>
>>>       @staticmethod
>>>       def get(key):
>>>           """
>>>           general purpose method to get data from the cache
>>>
>>>           :param key (string) key of the data to be fetched
>>>           :return value (any type) data to be returned from the cache
>>>           """
>>>           return region.get(key)
>>>
>>>
>>>       @staticmethod
>>>       def get_or_create(key):
>>>           """
>>>           General purpose method to get data from the cache. If the value does not exist, it creates a list
>>>
>>>           :param: key (string) key of the data to be fetched
>>>           :return value (any type) data to be returned from the cache
>>>           """
>>>           return region.get_or_create(key, list)
>>>
>>>       @staticmethod
>>>       def set_job_predictions(rank_list):
>>>           Cache.save("job_predictions", rank_list)
>>>
>>>       @staticmethod
>>>       def get_job_predictions():
>>>           return Cache.get("job_predictions")
>>>
>>
>> I get the strong impression that you're reinventing wheels and doing it
>> so badly that they're triangular.  Have you tried pypi
>> https://pypi.python.org/pypi for proven code that could do the job for you?
>>
>> --
>> My fellow Pythonistas, ask not what our language can do for you, ask
>> what you can do for our language.
>>
>> Mark Lawrence
>
> @Mark
> I don't understand your remark. Pypi is a repository. What this has to do with my problem?
>

It might well have working code that you can just use, instead of a 
dreadful pile of code that has the appalling smell of Java coming out of 
every seam.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#100973

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2015-12-29 17:49 -0500
Message-ID<mailman.62.1451429362.11925.python-list@python.org>
In reply to#100962
On Tue, 29 Dec 2015 09:27:02 -0800 (PST), xeon Mailinglist
<xeonmailinglist@gmail.com> declaimed the following:


>
>Here is the full class that I use to store the data.
>
>from dogpile.cache import make_region
>
>
># my_dictionary = {}
>region = make_region().configure('dogpile.cache.memory')
># arguments={"cache_dict":my_dictionary})
>class Cache:
>
>    @staticmethod
>    def save(key, value):
>        """
>        general purpose method to save data (value) in the cache
>
>        :param key (string) key of the value to be saved in cache
>        :param value (any type) the value to be saved
>        """
>        region.set(key, value)
>
>    @staticmethod
>    def get(key):
>        """
>        general purpose method to get data from the cache
>
>        :param key (string) key of the data to be fetched
>        :return value (any type) data to be returned from the cache
>        """
>        return region.get(key)
>
>
>    @staticmethod
>    def get_or_create(key):
>        """
>        General purpose method to get data from the cache. If the value does not exist, it creates a list
>
>        :param: key (string) key of the data to be fetched
>        :return value (any type) data to be returned from the cache
>        """
>        return region.get_or_create(key, list)
>
>    @staticmethod
>    def set_job_predictions(rank_list):
>        Cache.save("job_predictions", rank_list)
>
>    @staticmethod
>    def get_job_predictions():
>        return Cache.get("job_predictions")

	You are defining a Python class in which EVERY method is a static
method... Smells like Java code to me...

	Delete the class definition line, shift all the methods left and
reference them as module attributes.

import theModule

keyx = theModule.get_key("a key")

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web