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


Groups > comp.lang.python > #51054

odd behavoiur seen

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.mixmin.net!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Mon, 22 Jul 2013 13:36:41 -0500
From Chris Hinsley <chris.hinsley@gmail.com>
Newsgroups comp.lang.python
Date Mon, 22 Jul 2013 19:36:41 +0100
Message-ID <2013072219364160391-chrishinsley@gmailcom> (permalink)
MIME-Version 1.0
Content-Type text/plain; charset=iso-8859-1; format=flowed
Content-Transfer-Encoding 8bit
Subject odd behavoiur seen
User-Agent Unison/2.1.10
Lines 38
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-caBxi68SwwYEyeUCftd/JZGfphJGhqZwY5P4pMUmC7HQA1R7TNniGYI5UuDnGPN5GRuaoKgda6ufvEM!UBzt0lwD7ebVlcKQ9I2gqtuoFlEbQG4LRkywRc8hW3NkNaP8uy4MfAxLrM2uaDT/kqQ=
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2172
Xref csiph.com comp.lang.python:51054

Show key headers only | View raw


Folks, I have this decorator:

def memoize(maxsize):
    def _memoize(func):
        lru_cache = {}
        lru_list = []

        def memoizer(*args, **kwargs):
            key = str(args) + str(kwargs)
            if key in lru_cache:
                lru_list.remove(key)
                lru_list.append(key)
                return lru_cache[key]
            print len(lru_list),
            if len(lru_list) >= maxsize:
                del(lru_cache[lru_list[0]])
                del(lru_list[0])
            ret = func(*args, **kwargs)
            lru_cache[key] = ret
            lru_list.append(key)
            return ret
        return memoizer
    return _memoize

I didn't used to do the 'len(lru_list) >= maxsize' just '==' and 
noticed it sailing past the max number of entries, so put in the print 
statement, and now I see it ocationally printing a value 1 larger than 
maxsize !!!

So if I use it as '@memoize(64)' I see some 65's in the output ! I'm at 
a loss to explain it, does anyone knows why ? Is it a bug or some 
threading issue ? I'm not useing threads BTW, and I've noticed this in 
both running it with Python or Pypy.

Best Regards

Chris

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

odd behavoiur seen Chris Hinsley <chris.hinsley@gmail.com> - 2013-07-22 19:36 +0100
  Re: odd behavoiur seen Chris Hinsley <chris.hinsley@gmail.com> - 2013-07-22 19:42 +0100
    Re: odd behavoiur seen Peter Otten <__peter__@web.de> - 2013-07-22 21:47 +0200
      Re: odd behavoiur seen Chris Hinsley <chris.hinsley@gmail.com> - 2013-07-22 21:12 +0100

csiph-web