Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #67957 > unrolled thread
| Started by | Larry Martell <larry.martell@gmail.com> |
|---|---|
| First post | 2014-03-06 17:21 -0500 |
| Last post | 2014-03-06 17:21 -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.
Re: script uses up all memory Larry Martell <larry.martell@gmail.com> - 2014-03-06 17:21 -0500
| From | Larry Martell <larry.martell@gmail.com> |
|---|---|
| Date | 2014-03-06 17:21 -0500 |
| Subject | Re: script uses up all memory |
| Message-ID | <mailman.7878.1394144487.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web