Getting StopIteration exceptions while iterator isn't fully exhausted

Viewed 38

I'm just curious about strange behavior since it seems working well yet. Generally, I have the simple job:

 def weather_history_obtain_job(rows=itertuples):
        
    for key in mails.api_keys:
        for _ in range(490):
            try:
                row = next(rows)
            except StopIteration:
                print('The end of active tradepoint dates is reached!')
                return

            weather_frame = get_tp_weather_history(row,key)
            weather_frame[_columns].to_csv('weather_history.csv', mode='a', header=None)

Scheduled by the same name python library:

itertuples = dates_frame.itertuples()
schedule.every().day.at("07:30").do(weather_history_obtain_job)

while True:
    schedule.run_pending()
    tm.sleep(15)

So what I've got is several exception block prints, one per day of execution:

The end of active tradepoint dates is reached!
The end of active tradepoint dates is reached!

And my question is how come execution to the exception block, while, obviously, the iterator has not achieved the end, and execution continues just like I was expected it to take more than two days to complete the task?

0 Answers
Related