script uses up all memory

Chris Angelico rosuav at gmail.com
Thu Mar 6 23:11:37 CET 2014


On Fri, Mar 7, 2014 at 8:56 AM, Larry Martell <larry.martell at 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

ChrisA



More information about the Python-list mailing list