Skip to content

Commit

Permalink
fix: dictionary changed size during iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoOwO committed May 14, 2021
1 parent b8b6d25 commit 3f34011
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,17 @@ def get_channel_name_by_video_id(video_id):
def clear_chat():
utils.log(f" Running chat instance clearing task.")
global chats
to_del = []
for video_id in chats:
if chats[video_id].is_finished():
if const.CHAT_CALLBACK_AFTER_EXPIRY:
channel_name = get_channel_name_by_video_id(video_id)
chat_callback.callback(chats[video_id], channel_name=channel_name, video_id=video_id)
chats.pop(video_id)
utils.log(f" Chat instance {video_id} has been cleared.")
to_del.append(video_id)
utils.log(f" Chat instance {video_id} has been queued to be cleared.")
for video_id in to_del:
chats.pop(video_id)
utils.log(f" Chat instance {video_id} has been cleared.")

chat_expiry_task = utils.RepeatedTimer(const.CHAT_TASK_CLEAR_INTERVAL, clear_chat)

Expand Down

0 comments on commit 3f34011

Please sign in to comment.