commit de6f5a8e0357b201b5f0ffe20195b36cad66824d
parent eaa4de33541a56af049b8d48b92f206ed47f785a
Author: SomberNight <somber.night@protonmail.com>
Date: Wed, 10 Mar 2021 18:07:15 +0100
{daemon,wallet}|.stop: small clean-up
Diffstat:
2 files changed, 8 insertions(+), 15 deletions(-)
diff --git a/electrum/daemon.py b/electrum/daemon.py
@@ -32,13 +32,11 @@ import threading
from typing import Dict, Optional, Tuple, Iterable, Callable, Union, Sequence, Mapping, TYPE_CHECKING
from base64 import b64decode, b64encode
from collections import defaultdict
-import concurrent
-from concurrent import futures
import json
import aiohttp
from aiohttp import web, client_exceptions
-from aiorpcx import TaskGroup, timeout_after, TaskTimeout
+from aiorpcx import TaskGroup, timeout_after, TaskTimeout, ignore_after
from . import util
from .network import Network
@@ -560,14 +558,11 @@ class Daemon(Logger):
for k, wallet in self._wallets.items():
await group.spawn(wallet.stop())
self.logger.info("stopping network and taskgroup")
- try:
- async with timeout_after(2):
- async with TaskGroup() as group:
- if self.network:
- await group.spawn(self.network.stop(full_shutdown=True))
- await group.spawn(self.taskgroup.cancel_remaining())
- except TaskTimeout:
- pass
+ async with ignore_after(2):
+ async with TaskGroup() as group:
+ if self.network:
+ await group.spawn(self.network.stop(full_shutdown=True))
+ await group.spawn(self.taskgroup.cancel_remaining())
fut = asyncio.run_coroutine_threadsafe(stop_async(), self.asyncio_loop)
fut.result()
diff --git a/electrum/wallet.py b/electrum/wallet.py
@@ -46,7 +46,7 @@ import itertools
import threading
import enum
-from aiorpcx import TaskGroup, timeout_after, TaskTimeout
+from aiorpcx import TaskGroup, timeout_after, TaskTimeout, ignore_after
from .i18n import _
from .bip32 import BIP32Node, convert_bip32_intpath_to_strpath, convert_bip32_path_to_list_of_uint32
@@ -357,14 +357,12 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
async def stop(self):
"""Stop all networking and save DB to disk."""
try:
- async with timeout_after(5):
+ async with ignore_after(5):
await super().stop()
if self.network:
if self.lnworker:
await self.lnworker.stop()
self.lnworker = None
- except TaskTimeout:
- pass
finally: # even if we get cancelled
if any([ks.is_requesting_to_be_rewritten_to_wallet_file for ks in self.get_keystores()]):
self.save_keystore()