{daemon,wallet}|.stop: small clean-up
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user