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


Groups > comp.lang.python > #67957

Re: script uses up all memory

References <CACwCsY65gpn_Zx78wquE-rmrZu10pu9GYbzWd-Y3ypzHsMb2Yw@mail.gmail.com> <CACwCsY4nxs-4WmKboA9mOwrjQjXKXmaBPTuuq0GSmjzEpA3efQ@mail.gmail.com> <CAPTjJmr=1CW3BP23x2RTmnfxWppUNz_m_jHp=6aBTF0qj3YkVw@mail.gmail.com>
Date 2014-03-06 17:21 -0500
Subject Re: script uses up all memory
From Larry Martell <larry.martell@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.7878.1394144487.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Mar 6, 2014 at 5:11 PM, Chris Angelico <rosuav@gmail.com> wrote:
> On Fri, Mar 7, 2014 at 8:56 AM, Larry Martell <larry.martell@gmail.com> wrote:
>> I figured out what is causing this. Each pass through the loop it does:
>>
>> self.tools = Tool.objects.filter(ip__isnull=False)
>>
>> And that is what is causing the memory consumption. If I move that
>> outside the loop and just do that once the memory issue goes away. Now
>> I need to figure out why this is happening and how to prevent it as
>> they do want to query the db each pass through the loop in case it has
>> been updated.
>
> Interesting. So the next thing to do is to look into the
> implementation of that. Does it allocate database resources and not
> free them? Does it have internal reference loops?
>
> Something to try: Put an explicit gc.collect() call into the loop. If
> that solves your problem, you have a refloop somewhere (and you can
> properly fix it by explicitly breaking the loop). If that keeps
> returning large numbers, and especially if it populates gc.garbage
> with a whole lot of stuff, then you definitely have refloops.
>
> http://docs.python.org/2/library/gc.html


First I added del(self.tools) before the Django call. That did not
stop the memory consumption. Then I added a call to gc.collect() after
the del and that did solve it. gc.collect() returns 0 each time, so
I'm going to declare victory and move on. No time to dig into the
Django code. Thanks.

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


Thread

Re: script uses up all memory Larry Martell <larry.martell@gmail.com> - 2014-03-06 17:21 -0500

csiph-web