def thumbnail_generator(image_dict):
    """Generates a thumbnail. Loads the data slowly."""
    # Why is it a generator-function and not just a function?
    thumb_dir = os.path.dirname(image_dict['data']['thumb'])
    if not os.path.exists(thumb_dir):
        os.mkdir(thumb_dir)
    loader = gtk.gdk.PixbufLoader()
    try:
        fin = open(image_dict['data']['filename'], 'rb')
        while 1:
            data = fin.read(32768)
            if data:
                loader.write(data)
                yield None
            else:
                break
        pixbuf = loader.get_pixbuf()
        if pixbuf is None:
            raise ValueError(_("Invalid picture"))
        scaled = scale_image(pixbuf, image_dict['data']['thumb'])
        loader.close()
        loader = None
        fin.close()
        gc.collect()
        yield (image_dict, scaled)
    except (__HOLE__, ValueError), exc:
        print image_dict['data']['filename'] + ': ' + str(exc)
        loader.close()
        loader = None
        raise
dataset/ETHPy150Open thesamet/webilder/src/webilder/thumbs.py/thumbnail_generator