def safer_yield_per(query, id_field, start_id, count):
 cur_id = start_id
 while True:
  results = query.filter((id_field >= cur_id)).order_by(id_field).limit(count).all()
  if (not results):
   return
  for result in results:
   (yield result)
  cur_id = (results[(-1)].id + 1)

def safer_yield_per ( query , id_field , start_id , count ) : cur_id = start_id while True : results = query . filter ( ( id_field >= cur_id ) ) . order_by ( id_field ) . limit ( count ) . all ( ) if ( not results ) : return for result in results : ( yield result ) cur_id = ( results [ ( - 1 ) ] . id + 1 )
incautious execution of for result in query .