resolve-dns-nxdomain speed improvement

Do not wait until all the tasks are finished, scedule new task
right after another task is finished
This commit is contained in:
ValdikSS 2022-08-07 19:06:35 +03:00
parent 4d08301ca6
commit 40e6053bed

View File

@ -63,7 +63,9 @@ async def runTasksWithProgress(tasks, tasknumber, concurrent_tasks):
old_progress = 0 old_progress = 0
ret = [] ret = []
# this line actually "runs" coroutine
tasklist = list(itertools.islice(tasks, concurrent_tasks)) tasklist = list(itertools.islice(tasks, concurrent_tasks))
tasklist_next = []
while tasklist: while tasklist:
for task in asyncio.as_completed(tasklist): for task in asyncio.as_completed(tasklist):
ret.append(await task) ret.append(await task)
@ -71,7 +73,12 @@ async def runTasksWithProgress(tasks, tasknumber, concurrent_tasks):
if old_progress < progress: if old_progress < progress:
print("{}%...".format(progress), end='\r', file=sys.stderr, flush=True) print("{}%...".format(progress), end='\r', file=sys.stderr, flush=True)
old_progress = progress old_progress = progress
tasklist = list(itertools.islice(tasks, concurrent_tasks))
for newtask in tasks: # this line actually "runs" coroutine
tasklist_next.append(newtask)
break
tasklist = tasklist_next
tasklist_next = []
print(file=sys.stderr) print(file=sys.stderr)
return ret return ret