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


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

Re:Generator using item[n-1] + item[n] memory

Started byDave Angel <davea@davea.name>
First post2014-02-14 18:03 -0500
Last post2014-02-14 18:03 -0500
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re:Generator using item[n-1] + item[n] memory Dave Angel <davea@davea.name> - 2014-02-14 18:03 -0500

#66337 — Re:Generator using item[n-1] + item[n] memory

FromDave Angel <davea@davea.name>
Date2014-02-14 18:03 -0500
SubjectRe:Generator using item[n-1] + item[n] memory
Message-ID<mailman.6942.1392418793.18130.python-list@python.org>
 Nick Timkovich <prometheus235@gmail.com> Wrote in message:
> 
 def biggen():
    sizes = 1, 1, 10, 1, 1, 10, 10, 1, 1, 10, 10, 20, 1, 1, 20,
 20, 1, 1
    for size in sizes:
        data = [1] * int(size * 1e6)
        #time.sleep(1)
        yield data

> def consumer():
    for data in biggen():
        rusage = resource.getrusage(resource.RUSAGE_SELF)
        peak_mb = rusage.ru_maxrss/1024.0
        print('Peak: {0:6.1f} MB, Data Len: {1:6.1f} M'.format(
                peak_mb, len(data)/1e6))
        #print(memory_usage())

        data = None  # go
        del data     # away
        gc.collect() # please.


............
I think one problem is in the generator itself.  After the yield,
 set data=None

-- 
DaveA

[toc] | [standalone]


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


csiph-web