From f0734e1190630f4cefa4a2028884413f54310f82 Mon Sep 17 00:00:00 2001 From: Lesmiscore Date: Fri, 25 Feb 2022 13:22:17 +0900 Subject: [PATCH] [downloader/fragment] Fix problem where multiple threads can share one iterator which causes "ValueError: generator already executing" error Closes #2881 --- yt_dlp/downloader/fragment.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/yt_dlp/downloader/fragment.py b/yt_dlp/downloader/fragment.py index 082581b54d..7b213cd5f8 100644 --- a/yt_dlp/downloader/fragment.py +++ b/yt_dlp/downloader/fragment.py @@ -410,17 +410,16 @@ class FragmentFD(FileDownloader): def bindoj_result(future): return future.result() + def interrupt_trigger_iter(fg): + for f in fg: + if not interrupt_trigger[0]: + break + yield f + spins = [] for idx, (ctx, fragments, info_dict) in enumerate(args): tpe = FTPE(math.ceil(max_workers / max_progress)) - - def interrupt_trigger_iter(): - for f in fragments: - if not interrupt_trigger[0]: - break - yield f - - job = tpe.submit(thread_func, idx, ctx, interrupt_trigger_iter(), info_dict, tpe) + job = tpe.submit(thread_func, idx, ctx, interrupt_trigger_iter(fragments), info_dict, tpe) spins.append((tpe, job)) result = True