@@ -284,7 +284,7 @@ async def run_download(self):
284284
285285 def _format_results (self , retvals , main_pb ):
286286 # Squash all nested lists into a single flat list
287- if retvals :
287+ if retvals and isinstance ( retvals [ 0 ], list ) :
288288 retvals = list (reduce (list .__add__ , retvals ))
289289 errors = sum ([isinstance (i , FailedDownload ) for i in retvals ])
290290 if errors :
@@ -435,23 +435,28 @@ async def _run_ftp_download(self, main_pb):
435435
436436 async def _run_from_queue (self , queue , tokens , main_pb , * , session = None ):
437437 futures = []
438- while not queue .empty ():
439- get_file = await queue .get ()
440- token = await tokens .get ()
441- file_pb = self .tqdm if self .config .file_progress else False
442- future = asyncio .create_task (get_file (session , token = token , file_pb = file_pb ))
443-
444- def callback (token , future , main_pb ):
445- try :
446- tokens .put_nowait (token )
447- # Update the main progressbar
448- if main_pb and not future .exception ():
449- main_pb .update (1 )
450- except asyncio .CancelledError :
451- return
452-
453- future .add_done_callback (partial (callback , token , main_pb = main_pb ))
454- futures .append (future )
438+ try :
439+ while not queue .empty ():
440+ get_file = await queue .get ()
441+ token = await tokens .get ()
442+ file_pb = self .tqdm if self .config .file_progress else False
443+ future = asyncio .create_task (get_file (session , token = token , file_pb = file_pb ))
444+
445+ def callback (token , future , main_pb ):
446+ try :
447+ tokens .put_nowait (token )
448+ # Update the main progressbar
449+ if main_pb and not future .exception ():
450+ main_pb .update (1 )
451+ except asyncio .CancelledError :
452+ return
453+
454+ future .add_done_callback (partial (callback , token , main_pb = main_pb ))
455+ futures .append (future )
456+
457+ except asyncio .CancelledError :
458+ for task in futures :
459+ task .cancel ()
455460
456461 return futures
457462
0 commit comments