script uses up all memory

Kent Engström kent at lysator.liu.se
Fri Mar 14 15:10:07 CET 2014


Larry Martell <larry.martell at gmail.com> writes:
> 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.

Django saves a copy of every executed SQL query if it is in debug mode
(if the DEBUG setting is true). See

https://docs.djangoproject.com/en/dev/faq/models/#why-is-django-leaking-memory

Regards,
/ Kent Engström, Lysator




More information about the Python-list mailing list