Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
Find and fix a django "memleak"
import objgraph
import sys
import logging
from django.http import HttpResponse
from .models import FirstModel
logger = logging.getLogger(__name__)
class LoggerWriter:
def __init__(self, logger):
self.logger = logger
def write(self, message):
if message != '\n':
def my_view(request):
sys.stdout = LoggerWriter(logger)
huge_queryset = FirstModel.objects.all()
f = open('dumb.dump', 'w')
row = 0
for record in huge_queryset:
print >>f, record
row += 1
if not (row % 1000):
return HttpResponse('Dumb dump completed!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.