Log thread's error instead of stopping the whole queue.

This commit is contained in:
voussoir 2022-08-14 10:43:13 -07:00
parent 54281d52c2
commit 2318b978c9
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -5,6 +5,7 @@ import shutil
import sys import sys
import threading import threading
import time import time
import traceback
from voussoirkit import betterhelp from voussoirkit import betterhelp
from voussoirkit import bytestring from voussoirkit import bytestring
@ -175,14 +176,15 @@ def threaded_dl(
kwargss.append(kwargs) kwargss.append(kwargs)
pool.add_many(kwargss) pool.add_many(kwargss)
status = 0
for job in pool.result_generator(): for job in pool.result_generator():
if job.exception: if job.exception:
ui_stop_event.set() log.error(traceback.format_exc())
ui_thread.join() status = 1
raise job.exception
ui_stop_event.set() ui_stop_event.set()
ui_thread.join() ui_thread.join()
return status
def ui_thread_func(meter, pool, stop_event): def ui_thread_func(meter, pool, stop_event):
if pipeable.stdout_pipe(): if pipeable.stdout_pipe():
@ -207,7 +209,7 @@ def threaded_dl_argparse(args):
if bytespersecond is not None: if bytespersecond is not None:
bytespersecond = bytestring.parsebytes(bytespersecond) bytespersecond = bytestring.parsebytes(bytespersecond)
threaded_dl( return threaded_dl(
urls, urls,
bytespersecond=bytespersecond, bytespersecond=bytespersecond,
filename_format=args.filename_format, filename_format=args.filename_format,
@ -216,8 +218,6 @@ def threaded_dl_argparse(args):
timeout=args.timeout, timeout=args.timeout,
) )
return 0
@vlogging.main_decorator @vlogging.main_decorator
def main(argv): def main(argv):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()