From d2d4917a5334bc3de3ddf255a61289072abfe6a6 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Wed, 11 Aug 2021 18:49:47 -0700 Subject: [PATCH] detect and handle task cancellations semi-properly --- respodns/dns.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/respodns/dns.py b/respodns/dns.py index 1b04006..b65b4b4 100644 --- a/respodns/dns.py +++ b/respodns/dns.py @@ -113,7 +113,7 @@ def process_result(res, ip, check, opts: Options): async def try_ip(db, server_ip, checks, opts: Options): from .util import make_pooler - from asyncio import sleep + from asyncio import sleep, CancelledError entries = [] deferred = [] @@ -130,7 +130,11 @@ async def try_ip(db, server_ip, checks, opts: Options): def finisher(done, pending): nonlocal success for task in done: - res, ip, check = task.result() + try: + res, ip, check = task.result() + except CancelledError: + success = False + break entry = process_result(res, ip, check, opts) map(maybe_put_ip, entry.addrs) entries.append(entry)