you can probably get rid of that function and improve code readability. it should be pretty apparent that when len(batch) < page_size, you don't need to read any more.