Re: EOFError: marshal data too short -- causes?

2015-12-29 Thread Glenn Linderman

On 12/28/2015 11:19 PM, Terry Reedy wrote:

On 12/29/2015 1:50 AM, Glenn Linderman wrote:

Here's a sanatized stack trace off my web server:

   File ".../cgihelpers.py", line 10, in
 import cgitb
   File ".../py34/lib/python3.4/cgitb.py", line 24, in
 import inspect
   File ".../py34/lib/python3.4/inspect.py", line 54, in
 from dis import COMPILER_FLAG_NAMES as _flag_names
   File "", line 2237, in _find_and_load
   File "", line 2226, in _find_and_load_unlocked
   File "", line 1200, in _load_unlocked
   File "", line 1129, in _exec
   File "", line 1467, in exec_module
   File "", line 1570, in get_code
   File "", line 656, in _compile_bytecode
EOFError: marshal data too short


It worked this morning, and does this now.  I hadn't changed anything.


Since it crashes trying to unmarshal compiled dis bytecode, I would 
assume that the .pyc file is corrupted and remove it. Based on the 
above, it should be in

.../py34/lib/python3.4/__pycache__/dis.*.pyc
Python will then recompile dis and write a new .pyc file.



Thank you, thank you, thank you, thank you, thank you, thank you, thank 
you, thank you, thank you, thank you, thank you, thank you, thank you, 
thank you, thank you, thank you, thank you, thank you, thank you, thank 
you, thank you, thank you, thank you, thank you, thank you, thank you, 
thank you, thank you, thank you, thank you, thank you, thank you, thank 
you, thank you, thank you, thank you, thank you, thank you, thank you, 
thank you!


The site is working now, again.  Thank you, again.

Because of the File "" lines, and the fact that there were recent 
comments about frozen import stuff on python-dev, I was thinking that 
the corruption was at a lower level, and never thought to zap a .pyc.


OK, so I actually renamed it instead of zapping it.  Them, actually, 
there were both .pyc and .pyo.


Now the __pycache__ directory is full of .pyc and .pyo files (from the 
install? On April 19th? (the date on most of the files).  But:


areli...@areliabledomain.com [~/py34/lib/python3.4/__pycache__]# ll dis*
-rw-r--r-- 1 areliabl areliabl 14588 Dec 29 00:27 dis.cpython-34.pyc
-rw-r--r-- 1 areliabl areliabl  8192 Dec 28 19:16 dis.cpython-34.pyc-xxx
-rw-r--r-- 1 areliabl areliabl 14588 Apr 19  2015 dis.cpython-34.pyo-xxx

(I renamed the existing .py* files by appending -xxx).

So we can see that somehow, today at 19:16 (probably UTC) the dis.*.pyc 
file got chopped to 8192 bytes. That's a suspicious number, being a 
power of 2... but... I haven't updated Python since originally 
installing it on the web server, on April 19th.  So why would _that_ 
.pyc file have today's date? Because of UTC, the replacement has 
tomorrow's date :)  But it seems like it should have had Apr 19 2015 
like all the rest.


Except, all the rest don't have Apr 19 2015... most of them do, but 
there are a fair number from today, and a couple from Dec 15 (listed 
below).  I don't quickly see any others that are suspiciously exactly a 
power of 2!


But, under the assumption that the install created all these files in 
the first place, why would _any_ of them have newer dates?  I haven't 
gone around deleting any .pyc files since April.  And if they are 
already there, why would Python rebuild them? Isn't the point of the 
.pyc files to not need to recompile?  And even if the original build 
didn't build them, since I haven't touch the python sources on this web 
server for months, shouldn't all the files be months old, at least?


And isn't it rather suspicious that of the ones that are rebuilt, that 
all of them have exactly the same timestamp, rather than being sprinkled 
around with different dates?  Well, the two from Dec 15 have the same 
time, and all the ones from today have the same time. But that doesn't 
seem like some sort of "random error or access conflict accessing file 
causing it to be rebuilt"


Should I accuse my web host of playing with these files?  Are they 
backing up/restoring?  Are they simply touching the files? Is their 
infrastructure flaky such that whole groups of files get deleted now and 
then (and either rebuilt or restored with a different date)?



areli...@areliabledomain.com [~/py34/lib/python3.4/__pycache__]# find 
-mtime -240 -ls

113654924   20 drwxr-xr-x   2 areliabl areliabl20480 Dec 29 00:27 .
113639463   76 -rw-r--r--   1 areliabl areliabl76650 Dec 28 19:16 
./inspect.cpython-34.pyc
113639477   16 -rw-r--r--   1 areliabl areliabl14588 Dec 29 00:27 
./dis.cpython-34.pyc
113639458   16 -rw-r--r--   1 areliabl areliabl12361 Dec 28 19:16 
./ast.cpython-34.pyc
113639451   36 -rw-r--r--   1 areliabl areliabl32773 Dec 28 19:16 
./shutil.cpython-34.pyc
113639468   12 -rw-r--r--   1 areliabl areliabl10371 Dec 28 19:16 
./contextlib.cpython-34.pyc
113639469   16 -rw-r--r--   1 areliabl areliabl15916 Dec 28 19:16 
./lzma.cpython-34.pyc
113639475   16 -rw-r--r--   1 areliabl areliabl15130 Dec 28 19:16 
./bz2.cpython-34.pyc
113639486   68 -rw-r-

Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-29 Thread lee
On Monday, December 28, 2015 at 11:30:18 PM UTC+1, Cameron Simpson wrote:
> On 28Dec2015 01:34, Prince Udoka  wrote:
> >bu i have come up with a solution, that will work but encounter a problem in 
> >the set, giving set not manipulated correctly:
> >
> >def manipulate_data(kind, data):
> >if kind == 'list':
> >return list(data)[::-1]
> >elif kind == 'set':
> >return set(data)
> >elif kind == 'dictionary':
> >return dict.keys(data)
> >manipulate_data("list", range(1,6))
> >manipulate_data("set", {"a", "b", "c", "d", "e", "ANDELA", "TIA", "AFRICA"})
> >manipulate_data("dictionary", {"apples": 23, "oranges": 15, "mangoes": 3, 
> >"grapes": 45})
> >
> >the thing now is the function to use in adding "ANDELA", "TIA", "AFRICA"
> >pls 4give my use of language
> 
> You are very close. Let me remind you of the original task text:
> 
>   add items `"ANDELA"`, `"TIA"` and `"AFRICA"` to the set and return the 
>   resulting set
> 
> Your previous attempt (with hardwired values inside the function) actually 
> had 
> code to do it.
> 
> While you have pulled out all the hardwired values from the function (good) 
> and 
> put them in the external calls, note that the task explicitly says "add items 
> `"ANDELA"`, `"TIA"` and `"AFRICA"` to the set". So _those_ values _are_ 
> supposed to be hardwired inside the function - they are a fixed part of the 
> task. So move them back in, as in your previous attempt.
> 
> There is some ambiguity in that part of the question: should you return a 
> _new_ 
> set consistint of the original set plus the three new values, or simply add 
> the 
> three values to the original set? Your prior code modified the original set, 
> which may fit the task specification.
> 
> However, it is a common design objective that functions do not, _normally_, 
> modify their arguments. So, consider this code:
> 
>   set1 = {"a", "b", "c", "d", "e"}
>   set2 = manipulate_data("set", set1)
> 
> After running this, set2 should look like this:
> 
>   {"a", "b", "c", "d", "e", "ANDELA", "TIA", "AFRICA"}
> 
> (in some order -- sets are not ordered). However, what about set1? In your 
> current code, set1 is modified, so it will be the same. But you can imagine 
> that it would be more useful for the caller if set1 were unchanged.
> 
> In python, the convention is usually that if a function returns the new value 
> then it should not modify the original. So you should probably construct a 
> copy 
> of the original set and modify that:
> 
>   data = set(data)
>   ... add the new values ...
>   return data
> 
> Cheers,
> Cameron Simpson 

thumbs up Cameron  , you and others here are really wonderful 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-29 Thread Cameron Simpson

On 29Dec2015 00:49, lee  wrote:

thumbs up Cameron  , you and others here are really wonderful
https://mail.python.org/mailman/listinfo/python-list


Hi Lee,

While we're generally happy to help, these questions are better taken to the 
tutor list here:


 https://mail.python.org/mailman/listinfo/tutor

Please join that list and ask you questions there.

The "python-list" list is more for people who are already competent with Python 
and programming and who are asking broader questions. The tutor list is 
specificly aimed at people like yourself who are either very new to Python or 
new to programming (and learning to program in Python).


Note that I have directed replies to this specific message to myself, we're off 
topic for python-list now...


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread xeon Mailinglist
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()

   
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (Execution) Termination bit, Alternation bit.

2015-12-29 Thread Skybuck Flying



"Chris Angelico"  wrote in message 
news:mailman.62.1450799815.2237.python-l...@python.org...


On Wed, Dec 23, 2015 at 2:46 AM, Skybuck Flying  
wrote:

One idea which immediatly comes to mind to fix this problem is to offer a
"PushTerminationFlag" onto stack and then a "ClearTerminationFlag"
instruction.

Then a code section can be executed without breaking or terminating.

Once that's done the code would then call "PopTerminationFlag".

At least this offers some protection against arbitrarely breaking code
sections.


"
Here on python-list/comp.lang.python, we have all those high level
facilities.
"

Ok, if that were true, please solve the problem then with python code ! ;)

Bye,
 Skybuck.

--
https://mail.python.org/mailman/listinfo/python-list


Re: (Execution) Termination bit, Alternation bit.

2015-12-29 Thread Skybuck Flying



"Grant Edwards"  wrote in message news:n59k40$e27$1...@reader1.panix.com...

On 2015-12-21, Dennis Lee Bieber  wrote:

On Mon, 21 Dec 2015 13:40:21 +0100, "Skybuck Flying"
 declaimed the following:


The original idea I posted is less about sending a signal to another
processor.

It is more about how to break out of an instruction sequence.

Example of problem:

Main:
while Condition1 do
begin
   while Condition2 do
   begin
   while Condition3 do
   begin
   Routine1
   end
   end;
end;


I do hope this is the result of over simplification for the example, as
otherwise I'd turn it into

while C1 and  C2 and C3:
R1



"
Not that this means that all rest of what Skyhawk posted makes any
sense at all.  I've spent a lot of time programming on "bare metal",
in assembly, Pascal, PL/M, and C (including using coroutines and
various other "multi-thread" constructs with no OS support), and I
really don't see the utility of his initial suggestion.
"

Great that means you will understand the example below:

mov eax, 0
add eax, 10
mul eax, 4

There is an instruction sequence for you.

This instruction sequence is too long believe it or not.

The mission is to make the CPU break out of instruction 2 and execute 
something else.


How would you do it ?

Bye,
 Skybuck. 


--
https://mail.python.org/mailman/listinfo/python-list


Re: (Execution) Termination bit, Alternation bit.

2015-12-29 Thread Skybuck Flying



"Grant Edwards"  wrote in message news:n59k40$e27$1...@reader1.panix.com...

On 2015-12-21, Dennis Lee Bieber  wrote:

On Mon, 21 Dec 2015 13:40:21 +0100, "Skybuck Flying"
 declaimed the following:


The original idea I posted is less about sending a signal to another
processor.

It is more about how to break out of an instruction sequence.

Example of problem:

Main:
while Condition1 do
begin
   while Condition2 do
   begin
   while Condition3 do
   begin
   Routine1
   end
   end;
end;


I do hope this is the result of over simplification for the example, as
otherwise I'd turn it into

while C1 and  C2 and C3:
R1


"
That's not equivalent to what Skybuck posted.  Think about what
happens when Routine1 causes Condition1 and Condition2 to become false
but Condition3 remains true.
"

Thanks for pointing that out to him, it's funny to see that at least that 
part of the logic you understand ! ;)


"
Not that this means that all rest of what Skyhawk posted makes any
sense at all.
"

Perhaps it will help you if I tell you the following:

1. This is just pseudo code.
2. The conditions C1, C2, C3 can be functions/routines returning booleans.

Bye,
 Skybuck.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2015-12-29 Thread lee
On Tuesday, December 29, 2015 at 11:48:42 AM UTC+1, Cameron Simpson wrote:
> On 29Dec2015 00:49, lee wrote:
> >thumbs up Cameron  , you and others here are really wonderful
> >https://mail.python.org/mailman/listinfo/python-list
> 
> Hi Lee,
> 
> While we're generally happy to help, these questions are better taken to the 
> tutor list here:
> 
>   https://mail.python.org/mailman/listinfo/tutor
> 
> Please join that list and ask you questions there.
> 
> The "python-list" list is more for people who are already competent with 
> Python 
> and programming and who are asking broader questions. The tutor list is 
> specificly aimed at people like yourself who are either very new to Python or 
> new to programming (and learning to program in Python).
> 
> Note that I have directed replies to this specific message to myself, we're 
> off 
> topic for python-list now...
> 
> Cheers,
> Cameron Simpson 


thanks Cameron,
i really appreciate your polite response and effort, i will join that list as 
you suggested.
Thanks again  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (Execution) Termination bit, Alternation bit.

2015-12-29 Thread Steven D'Aprano
On Tue, 29 Dec 2015 10:25 pm, Skybuck Flying wrote:

> Great that means you will understand the example below:
> 
> mov eax, 0
> add eax, 10
> mul eax, 4
> 
> There is an instruction sequence for you.


Skybuck, this is completely off-topic for a Python forum like this.




-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: EOFError: marshal data too short -- causes?

2015-12-29 Thread D'Arcy J.M. Cain
On Tue, 29 Dec 2015 00:01:00 -0800
Glenn Linderman  wrote:
> OK, so I actually renamed it instead of zapping it.  Them, actually, 

Really, just zap them.  They are object code.  Even if you zap a
perfectly good .pyc file a perfectly good one will be re-created as
soon as you import it.  No need to clutter up you file system.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list


yaxis

2015-12-29 Thread damien . ishacian
hello I would only change the scale of the y-axis, how to deal with 
matplotlib.pyplot or another library ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: yaxis

2015-12-29 Thread Mark Lawrence

On 29/12/2015 14:25, damien.ishac...@gmail.com wrote:

hello I would only change the scale of the y-axis, how to deal with 
matplotlib.pyplot or another library ?



Please show us your code.  The best way to deal with any library is to 
read the docs so start here http://matplotlib.org/contents.html


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

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread xeon Mailinglist
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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread Peter Otten
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.



-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread Mark Lawrence

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

--
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread xeon Mailinglist
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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread xeon Mailinglist
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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread xeon Mailinglist
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")

-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread Peter Otten
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...

-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread xeon Mailinglist
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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python.Exe Problem

2015-12-29 Thread Daniel Lee
Hello,

When I try to run python.exe on my computer with Windows 8, I get the
following error:

"Python.exe - Entry Point Not Found"

"The Procedure entry point ?terminate@@YAXXZ could not be located in the
dynamic link library C:\Program Files\Python3.5\python.exe."

What does this error mean and how can I fix it?

Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread xeon Mailinglist
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?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: yaxis

2015-12-29 Thread Peter Pearson
On Tue, 29 Dec 2015 06:25:49 -0800 (PST), damien.ishac...@gmail.com wrote:

> hello I would only change the scale of the y-axis, how to deal with
> matplotlib.pyplot or another library ?

Here's a function I use.  ax is an "axes" object, which you can get
by calling the get-current-axes (gca()) method of some plot object,
for example

from matplotlib import pyplot as plt

expand_limits(plt.gca(), 0.08)
plt.show()

Anyway, here's the function:

def expand_limits(ax, factor):
"""Expand the limits on a plotting area by the specified factor.
"""
def expand(xmin, xmax):
d = xmax - xmin
return xmin - 0.5*factor*d, xmax + 0.5*factor*d
ax.set_xlim(*expand(*ax.get_xlim()))
ax.set_ylim(*expand(*ax.get_ylim()))

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread Peter Otten
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")

>>> region.backend


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


-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread Mark Lawrence

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

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python.Exe Problem

2015-12-29 Thread Terry Reedy

On 12/29/2015 11:24 AM, Daniel Lee wrote:

Hello,

When I try to run python.exe on my computer with Windows 8,


Which exact version?  From what source?  How did you download (from 
where) or compile?  How did you install?  How do you try to run it?



I get the following error:

"Python.exe - Entry Point Not Found"

"The Procedure entry point ?terminate@@YAXXZ could not be located in the
dynamic link library C:\Program Files\Python3.5\python.exe."


Google return 76000 hits for 'terminate@@YAXXZ', so this appears to not 
be a unique issue in some form or another.



What does this error mean and how can I fix it?


It seems like your installed python.exe is corrupt.  Make sure you have 
a final release.  I would re-install, possibly after re-downloading from 
python.org.  If you download from anywhere else, *they* are responsible 
for getting the compile options correct.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: EOFError: marshal data too short -- causes?

2015-12-29 Thread Terry Reedy

On 12/29/2015 3:01 AM, Glenn Linderman wrote:


Now the __pycache__ directory is full of .pyc and .pyo files (from the
install?


The installer optionally runs compileall on /Lib and recursively on its 
subpackages.  The option defaults to 'yes', at least for 'install for 
everyone', as writing files within the default Program Files location 
requires Admin permission.


On April 19th? (the date on most of the files).  But:


areli...@areliabledomain.com [~/py34/lib/python3.4/__pycache__]# ll dis*
-rw-r--r-- 1 areliabl areliabl 14588 Dec 29 00:27 dis.cpython-34.pyc
-rw-r--r-- 1 areliabl areliabl  8192 Dec 28 19:16 dis.cpython-34.pyc-xxx
-rw-r--r-- 1 areliabl areliabl 14588 Apr 19  2015 dis.cpython-34.pyo-xxx

(I renamed the existing .py* files by appending -xxx).

So we can see that somehow, today at 19:16 (probably UTC) the dis.*.pyc
file got chopped to 8192 bytes. That's a suspicious number, being a
power of 2... but... I haven't updated Python since originally
installing it on the web server, on April 19th.  So why would _that_
.pyc file have today's date? Because of UTC, the replacement has
tomorrow's date :)  But it seems like it should have had Apr 19 2015
like all the rest.


I updated to 2.7.11, 3.4.4, and 3.5.1 a couple of weeks ago, so the 
timestamps are all fresh.  So I don't know what happened with 3.4.3 
timestamps from last April and whether Windows itself touches the files. 
 I just tried importing a few and Python did not.



And isn't it rather suspicious that of the ones that are rebuilt, that
all of them have exactly the same timestamp, rather than being sprinkled
around with different dates?  Well, the two from Dec 15 have the same
time, and all the ones from today have the same time. But that doesn't
seem like some sort of "random error or access conflict accessing file
causing it to be rebuilt"

Should I accuse my web host of playing with these files?  Are they
backing up/restoring?  Are they simply touching the files? Is their
infrastructure flaky such that whole groups of files get deleted now and
then (and either rebuilt or restored with a different date)?


You could ask, without 'accusing'.  Or you could re-run compileall 
yourself.  Or you could upgrade to 3.4.4 (I recommend this) and let the 
installer do so, or not.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: (Execution) Termination bit, Alternation bit.

2015-12-29 Thread Skybuck Flying



"Steven D'Aprano"  wrote in message 
news:5682892c$0$1587$c3e8da3$54964...@news.astraweb.com...


On Tue, 29 Dec 2015 10:25 pm, Skybuck Flying wrote:


Great that means you will understand the example below:

mov eax, 0
add eax, 10
mul eax, 4

There is an instruction sequence for you.



"
Skybuck, this is completely off-topic for a Python forum like this.
"

Not at all, these assembler statements can be replaced with python 
statements and then you have the exact same problem ! ;)


Bye,
 Skybuck. 


--
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread xeon Mailinglist
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 packa

Path problems when I am in bash

2015-12-29 Thread xeon Mailinglist
I have my source code inside the directory `medusa`, and my unit tests inside 
`tests` dir. Both dirs are inside `medusa-2.0` dir. Here is my file structure 
[1].

When I run my tests inside pycharm, everything works fine, but when I try to 
run my unit tests inside in the prompt [2], the 
`scheduler/predictionranking.py` can't find the `hdfs` import [3]. I have set 
my environment inside the `medusa-2.0` dir with the virtualenv, I even have set 
`medusa-2.0` in the PYTHON_PATH [4]. The error that I have is in [5]. 

The question is, why the import is not being done correctly?


[1] My file structure

medusa-2.0$ 
medusa (source code)
   hdfs.py
   scheduler (dir with my schedulers)
   predictionranking.py
tests (my unit tests)


[2] I run the unit test like this.

medusa-2.0$ python -v tests/testSimpleRun.py


[3] The header in `predictionranking.py`

import hdfs

def get_prediction_metrics(clusters, pinput):
"""
:param pinput (list) list of input paths

"""

input_size = hdfs.get_total_size(pinput)

[4] My python path

export MEDUSA_HOME=$HOME/repositories/git/medusa-2.0

export PYTHONPATH=${PYTHONPATH}:${MEDUSA_HOME}/medusa

[5] error that I have

medusa-2.0$ python -v tests/testSimpleRun.py
# /home/xeon/repositories/git/medusa-2.0/medusa/local.pyc matches 
/home/xeon/repositories/git/medusa-2.0/medusa/local.py
import medusa.local # precompiled from 
/home/xeon/repositories/git/medusa-2.0/medusa/local.pyc
# /home/xeon/repositories/git/medusa-2.0/medusa/ranking.pyc matches 
/home/xeon/repositories/git/medusa-2.0/medusa/ranking.py
import medusa.ranking # precompiled from 
/home/xeon/repositories/git/medusa-2.0/medusa/ranking.pyc
# /home/xeon/repositories/git/medusa-2.0/medusa/decors.pyc matches 
/home/xeon/repositories/git/medusa-2.0/medusa/decors.py
import medusa.decors # precompiled from 
/home/xeon/repositories/git/medusa-2.0/medusa/decors.pyc
# /home/xeon/repositories/git/medusa-2.0/medusa/settings.pyc matches 
/home/xeon/repositories/git/medusa-2.0/medusa/settings.py
import medusa.settings # precompiled from 
/home/xeon/repositories/git/medusa-2.0/medusa/settings.pyc
import medusa.scheduler # directory 
/home/xeon/repositories/git/medusa-2.0/medusa/scheduler
# /home/xeon/repositories/git/medusa-2.0/medusa/scheduler/__init__.pyc matches 
/home/xeon/repositories/git/medusa-2.0/medusa/scheduler/__init__.py
import medusa.scheduler # precompiled from 
/home/xeon/repositories/git/medusa-2.0/medusa/scheduler/__init__.pyc
# /home/xeon/repositories/git/medusa-2.0/medusa/scheduler/predictionranking.pyc 
matches 
/home/xeon/repositories/git/medusa-2.0/medusa/scheduler/predictionranking.py
import medusa.scheduler.predictionranking # precompiled from 
/home/xeon/repositories/git/medusa-2.0/medusa/scheduler/predictionranking.pyc
Traceback (most recent call last):
  File "tests/simpleRun.py", line 4, in 
from medusa.simplealgorithm import run_simple_execution
  File "/home/xeon/repositories/git/medusa-2.0/medusa/simplealgorithm.py", line 
8, in 
import accidentalfaults
  File "/home/xeon/repositories/git/medusa-2.0/medusa/accidentalfaults.py", 
line 5, in 
import hdfs
  File "/home/xeon/repositories/git/medusa-2.0/medusa/hdfs.py", line 6, in 

from system import execute_command
  File "/home/xeon/repositories/git/medusa-2.0/medusa/system.py", line 10, in 

from ranking import rank_clusters
  File "/home/xeon/repositories/git/medusa-2.0/medusa/ranking.py", line 9, in 

from scheduler.predictionranking import get_prediction_metrics
  File 
"/home/xeon/repositories/git/medusa-2.0/medusa/scheduler/predictionranking.py", 
line 6, in 
import hdfs
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-12-29 Thread Mark Lawrence

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

--
https://mail.python.org/mailman/listinfo/python-list


Re: (Execution) Termination bit, Alternation bit.

2015-12-29 Thread Chris Angelico
On Wed, Dec 30, 2015 at 8:43 AM, Skybuck Flying  wrote:
> Not at all, these assembler statements can be replaced with python
> statements and then you have the exact same problem ! ;)

Then do so. Give us an example where this problem occurs in pure Python.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Path problems when I am in bash

2015-12-29 Thread Karim



On 30/12/2015 00:21, xeon Mailinglist wrote:

I have my source code inside the directory `medusa`, and my unit tests inside 
`tests` dir. Both dirs are inside `medusa-2.0` dir. Here is my file structure 
[1].

When I run my tests inside pycharm, everything works fine, but when I try to 
run my unit tests inside in the prompt [2], the 
`scheduler/predictionranking.py` can't find the `hdfs` import [3]. I have set 
my environment inside the `medusa-2.0` dir with the virtualenv, I even have set 
`medusa-2.0` in the PYTHON_PATH [4]. The error that I have is in [5].

The question is, why the import is not being done correctly?


[1] My file structure

medusa-2.0$
medusa (source code)
hdfs.py
scheduler (dir with my schedulers)
predictionranking.py
tests (my unit tests)


[2] I run the unit test like this.

medusa-2.0$ python -v tests/testSimpleRun.py


[3] The header in `predictionranking.py`

import hdfs

def get_prediction_metrics(clusters, pinput):
 """
 :param pinput (list) list of input paths

 """

 input_size = hdfs.get_total_size(pinput)

[4] My python path

 export MEDUSA_HOME=$HOME/repositories/git/medusa-2.0

 export PYTHONPATH=${PYTHONPATH}:${MEDUSA_HOME}/medusa

[5] error that I have

medusa-2.0$ python -v tests/testSimpleRun.py
# /home/xeon/repositories/git/medusa-2.0/medusa/local.pyc matches 
/home/xeon/repositories/git/medusa-2.0/medusa/local.py
import medusa.local # precompiled from 
/home/xeon/repositories/git/medusa-2.0/medusa/local.pyc
# /home/xeon/repositories/git/medusa-2.0/medusa/ranking.pyc matches 
/home/xeon/repositories/git/medusa-2.0/medusa/ranking.py
import medusa.ranking # precompiled from 
/home/xeon/repositories/git/medusa-2.0/medusa/ranking.pyc
# /home/xeon/repositories/git/medusa-2.0/medusa/decors.pyc matches 
/home/xeon/repositories/git/medusa-2.0/medusa/decors.py
import medusa.decors # precompiled from 
/home/xeon/repositories/git/medusa-2.0/medusa/decors.pyc
# /home/xeon/repositories/git/medusa-2.0/medusa/settings.pyc matches 
/home/xeon/repositories/git/medusa-2.0/medusa/settings.py
import medusa.settings # precompiled from 
/home/xeon/repositories/git/medusa-2.0/medusa/settings.pyc
import medusa.scheduler # directory 
/home/xeon/repositories/git/medusa-2.0/medusa/scheduler
# /home/xeon/repositories/git/medusa-2.0/medusa/scheduler/__init__.pyc matches 
/home/xeon/repositories/git/medusa-2.0/medusa/scheduler/__init__.py
import medusa.scheduler # precompiled from 
/home/xeon/repositories/git/medusa-2.0/medusa/scheduler/__init__.pyc
# /home/xeon/repositories/git/medusa-2.0/medusa/scheduler/predictionranking.pyc 
matches 
/home/xeon/repositories/git/medusa-2.0/medusa/scheduler/predictionranking.py
import medusa.scheduler.predictionranking # precompiled from 
/home/xeon/repositories/git/medusa-2.0/medusa/scheduler/predictionranking.pyc
Traceback (most recent call last):
   File "tests/simpleRun.py", line 4, in 
 from medusa.simplealgorithm import run_simple_execution
   File "/home/xeon/repositories/git/medusa-2.0/medusa/simplealgorithm.py", line 8, 
in 
 import accidentalfaults
   File "/home/xeon/repositories/git/medusa-2.0/medusa/accidentalfaults.py", line 5, 
in 
 import hdfs
   File "/home/xeon/repositories/git/medusa-2.0/medusa/hdfs.py", line 6, in 

 from system import execute_command
   File "/home/xeon/repositories/git/medusa-2.0/medusa/system.py", line 10, in 

 from ranking import rank_clusters
   File "/home/xeon/repositories/git/medusa-2.0/medusa/ranking.py", line 9, in 

 from scheduler.predictionranking import get_prediction_metrics
   File 
"/home/xeon/repositories/git/medusa-2.0/medusa/scheduler/predictionranking.py", line 
6, in 
 import hdfs


Hello,

Can you try to set your PYTHONPATH like that:

export PYTHONPATH=${PYTHONPATH}:${MEDUSA_HOME}

Regards
Karim



--
https://mail.python.org/mailman/listinfo/python-list


Re: (Execution) Termination bit, Alternation bit.

2015-12-29 Thread Rustom Mody
On Saturday, December 19, 2015 at 11:26:55 PM UTC+5:30, Skybuck Flying wrote:
> Hello,
> 
> I'd like to see instruction execution enhanced with the following two ideas:
> 
> 1. A termination bit, and a terminator pointer.
> 2. A alternation bit, and a alternate pointer.
> 
> The purpose of these bits is as follows:
> 
> Before a processor/core executes an instruction both bits are examined.
> 
> 1. If the termination bit is set the instruction is not executed and instead 
> the processor sets the instruction pointer to the termination pointer.
> 2. If the alternation bit is set the instruction is not executed and instead 
> the processor sets the instruction pointer to the alternation pointer.
> 
> The idea behind this is support multi threading/parallelism better.
> 
> The idea is that Thread A could terminate Thread B immediately so that 
> Thread B does not continue execution.
> The idea is also that Thread A could influence Thread B to start executing a 
> different path.
> 
> Hopefully these bits are enough for operating systems to add support for 
> this. Some issues remaining could be items pushed on the stack.
> Perhaps operating system can deal with that, or perhaps compiler or perhaps 
> some other special instructions or software methods can be added.
> Hopefully operating systems can include data structures per thread that can 
> be loaded into the core, and into these bits and pointers so that it becomes 
> active.
> During a context switch these bits and pointers should be loaded 
> accordingly.
> So these two bits and these two pointers become part of the context.
> 
> I think these two features would be usefull to make multi-threading more 
> responsive and faster reaction time to changes/events occuring.
> 
> (Eventually it would be nice if these low level features would end up in 
> high level languages like Python ;))
> 
> Bye,
>   Skybuck.

By some coincidence was just reading:
from http://www.wordyard.com/2006/10/18/dijkstra-humble/

which has the following curious extract.
[Yeah its outlandish]

--
I consider the absolute worst programming construct to be
subroutine or the function. We've used it for over 50 years now
and we're still having difficulty reducing complexity. What if
the unthinkable were true? What if the subroutine was the cause
of all our problems? I can prove how the subroutine causes all
parts of our software to become coupled and as such cannot
support this as the basic building blocks of software.

I find the subroutine and all the technology around it (OOP,
functional, AOP, etc.) are like a sinking ship where you keep
throwing more lifeboats when what you really need is a new
boat. (The ship being the subroutine and the lifeboats are OOP,
funcional, AOP, etc.).

I posit a fourth "condition" for being able to produce better
software and that is being able to recognise what specifically
isn't working and be ready to ditch it. I see no indication of
this for at least another 20 or 70 years give or take 100 years.

Computing Industry's Best Kept Secret: The function is *NOT*
necessary to build software and may in fact be a bad tool.

:
:

[In response to questions of whats the answer to functions]

With functions, it's stack based. You have to wait until the
function returns in order to process the next function unless
it's an internal function. This is the first in, last out rule
just like a stack. I don't mean that functions are bad in of
themselves for certain things. I mean that maybe they're not the
*only* way. Just like different data structures have different
uses. Right now, everyone is using the function. Imagine if the
stack was the only data structure you could use. What a horrible
world. Yet this is what we have with the function.

Unix has pipes. These are queues. As data is piped, software on
both ends of the queue can execute at the same time. As data
passes from one end of the queue to the other, there is no
concept of execution point. Only data transformations and
transfers. Another example is the Internet where messages (real
ones) get passed back and forth. Simple idea that scales and is
in active use.

We've look into the stack based way of programming to
death. Maybe the queue or other data processing model can be
looked at, especially to solve concurrency. I feel it's a shame
that there are perfectly acceptable tools available that get
sidelined for the status quo.

BTW, history dictates that the function is not reusable. Well,
maybe it's reusable like sand is reusable to build glass. Once
it's actually used, it is forever transformed into something else
that can no longer be separated from the whole.
-- 
https://mail.python.org/mailman/listinfo/python-list