fix exceptions on shutdown, stop using cancel_tasks

This commit is contained in:
Victor Shyba 2022-03-09 14:24:16 -03:00
parent 2f1617eee4
commit a3da041412

View file

@ -5,7 +5,7 @@ import logging
import time import time
from collections import namedtuple from collections import namedtuple
from lbry.utils import resolve_host, async_timed_cache, cancel_tasks from lbry.utils import resolve_host, async_timed_cache
from lbry.wallet.stream import StreamController from lbry.wallet.stream import StreamController
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -145,8 +145,8 @@ class TrackerClient:
self.client = None self.client = None
self.transport = None self.transport = None
self.EVENT_CONTROLLER.close() self.EVENT_CONTROLLER.close()
cancel_tasks([task for _, task in self.tasks.values()]) while self.tasks:
self.tasks.clear() self.tasks.popitem()[1].cancel()
def hash_done(self, info_hash): def hash_done(self, info_hash):
self.tasks.pop(info_hash, None) self.tasks.pop(info_hash, None)
@ -156,9 +156,9 @@ class TrackerClient:
def on_hash(self, info_hash): def on_hash(self, info_hash):
if info_hash not in self.tasks: if info_hash not in self.tasks:
fut = asyncio.ensure_future(self.get_peer_list(info_hash)) task = asyncio.create_task(self.get_peer_list(info_hash))
fut.add_done_callback(lambda *_: self.hash_done(info_hash)) task.add_done_callback(lambda *_: self.hash_done(info_hash))
self.tasks[info_hash] = fut self.tasks[info_hash] = task
async def get_peer_list(self, info_hash, stopped=False): async def get_peer_list(self, info_hash, stopped=False):
found = [] found = []