def cursor_iter(cursor, sentinel, col_count):
 try:
  for rows in iter((lambda : cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)), sentinel):
   (yield [r[0:col_count] for r in rows])
 finally:
  cursor.close()

def cursor_iter ( cursor , sentinel , col_count ) : try : for rows in iter ( ( lambda : cursor . fetchmany ( GET_ITERATOR_CHUNK_SIZE ) ) , sentinel ) : ( yield [ r [ 0 : col_count ] for r in rows ] ) finally : cursor . close ( )
yields blocks of rows from a cursor and ensures the cursor is closed when done .