From 40e6053bed63fbfd2f038cf3dbd0631e60c73321 Mon Sep 17 00:00:00 2001 From: ValdikSS Date: Sun, 7 Aug 2022 19:06:35 +0300 Subject: [PATCH] resolve-dns-nxdomain speed improvement Do not wait until all the tasks are finished, scedule new task right after another task is finished --- scripts/resolve-dns-nxdomain.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/resolve-dns-nxdomain.py b/scripts/resolve-dns-nxdomain.py index 92fae72..88a0297 100755 --- a/scripts/resolve-dns-nxdomain.py +++ b/scripts/resolve-dns-nxdomain.py @@ -63,7 +63,9 @@ async def runTasksWithProgress(tasks, tasknumber, concurrent_tasks): old_progress = 0 ret = [] + # this line actually "runs" coroutine tasklist = list(itertools.islice(tasks, concurrent_tasks)) + tasklist_next = [] while tasklist: for task in asyncio.as_completed(tasklist): ret.append(await task) @@ -71,7 +73,12 @@ async def runTasksWithProgress(tasks, tasknumber, concurrent_tasks): if old_progress < progress: print("{}%...".format(progress), end='\r', file=sys.stderr, flush=True) 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) return ret