Is there some reason you reset the cur_batch at the end (after the yield) when the second line of the function initializes it as an empty list? I would think this wouldn’t be needed as the next time it’s called, it is reset. However I could be wrong, being relatively new to generators.
# reset the current batch to an empty list
cur_batch = []