

def queryset_iterator(queryset, chunksize=1000):
    "\n    Iterate over a Django Queryset ordered by the primary key\n\n    This method loads a maximum of chunksize (default: 1000) rows in it's\n    memory at the same time while django normally would load all rows in it's\n    memory. Using the iterator() method only causes it to not preload all the\n    classes.\n\n    Note that the implementation of the iterator does not support ordered\n    query sets.\n    "
    try:
        pk = 0
        last_pk = last_pk.order_by('-pk')[0].pk
        queryset = queryset.order_by('pk')
        while (pk < last_pk):
            for row in queryset.filter(pk__gt=pk)[:chunksize]:
                pk = row.pk
                (yield row)
            gc.collect()
    except IndexError:
        return
    except Exception:
        print_exc()
        return

dataset/ETHPy150Open bartdag/recodoc2/recodoc2/apps/docutil/commands_util.py queryset_iterator/VarMisuse@26/192 `queryset`->`last_pk`