Skip to content

Instantly share code, notes, and snippets.

@wiredfool
Created June 6, 2013 22:13
Show Gist options
  • Save wiredfool/5725422 to your computer and use it in GitHub Desktop.
Save wiredfool/5725422 to your computer and use it in GitHub Desktop.
actual test
from django.core.management.base import NoArgsCommand
from easy_thumbnails.files import generate_all_aliases
from photos.models import Photo
import time
import gc
import resource
#gc.enable()
#gc.set_debug(gc.DEBUG_LEAK)
def dump_garbage():
"""
show us what's the garbage about
"""
# force collection
print("\nGARBAGE:")
gc.collect()
print("\nGARBAGE OBJECTS:")
for x in gc.garbage:
s = str(x)
if len(s) > 80:
s = s[:80]
print(type(x), "\n ", s)
def time_function(func, *args, **kwargs):
st = time.time()
result = func(*args, **kwargs)
del result
print('It took %.2f seconds to generate all thumbnail aliases.' % (time.time() - st))
class Command(NoArgsCommand):
help = 'Generate thumbnail aliases for all photos'
def handle_noargs(self, **options):
START_TIME = time.time()
i = 0;
for p in Photo.objects.all():
generate_all_aliases(p.photo, include_global=True)
i+= 1
print("%i; RSS: %i; Obj: %i"%(i, resource.getrusage(resource.RUSAGE_SELF).ru_maxrss,
len(gc.get_objects())))
print('It took %.2f seconds to generate all thumbnails and aliases.' % (time.time() - START_TIME))
self.stdout.write('All thumbnail aliases generated succesfully.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment