{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 typing import Dict, Optional, Tuple, Iterable, Callable, Union, Sequence, Mapping, TYPE_CHECKING
|
||||||
from base64 import b64decode, b64encode
|
from base64 import b64decode, b64encode
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import concurrent
|
|
||||||
from concurrent import futures
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from aiohttp import web, client_exceptions
|
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 . import util
|
||||||
from .network import Network
|
from .network import Network
|
||||||
@@ -560,14 +558,11 @@ class Daemon(Logger):
|
|||||||
for k, wallet in self._wallets.items():
|
for k, wallet in self._wallets.items():
|
||||||
await group.spawn(wallet.stop())
|
await group.spawn(wallet.stop())
|
||||||
self.logger.info("stopping network and taskgroup")
|
self.logger.info("stopping network and taskgroup")
|
||||||
try:
|
async with ignore_after(2):
|
||||||
async with timeout_after(2):
|
async with TaskGroup() as group:
|
||||||
async with TaskGroup() as group:
|
if self.network:
|
||||||
if self.network:
|
await group.spawn(self.network.stop(full_shutdown=True))
|
||||||
await group.spawn(self.network.stop(full_shutdown=True))
|
await group.spawn(self.taskgroup.cancel_remaining())
|
||||||
await group.spawn(self.taskgroup.cancel_remaining())
|
|
||||||
except TaskTimeout:
|
|
||||||
pass
|
|
||||||
|
|
||||||
fut = asyncio.run_coroutine_threadsafe(stop_async(), self.asyncio_loop)
|
fut = asyncio.run_coroutine_threadsafe(stop_async(), self.asyncio_loop)
|
||||||
fut.result()
|
fut.result()
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import itertools
|
|||||||
import threading
|
import threading
|
||||||
import enum
|
import enum
|
||||||
|
|
||||||
from aiorpcx import TaskGroup, timeout_after, TaskTimeout
|
from aiorpcx import TaskGroup, timeout_after, TaskTimeout, ignore_after
|
||||||
|
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .bip32 import BIP32Node, convert_bip32_intpath_to_strpath, convert_bip32_path_to_list_of_uint32
|
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):
|
async def stop(self):
|
||||||
"""Stop all networking and save DB to disk."""
|
"""Stop all networking and save DB to disk."""
|
||||||
try:
|
try:
|
||||||
async with timeout_after(5):
|
async with ignore_after(5):
|
||||||
await super().stop()
|
await super().stop()
|
||||||
if self.network:
|
if self.network:
|
||||||
if self.lnworker:
|
if self.lnworker:
|
||||||
await self.lnworker.stop()
|
await self.lnworker.stop()
|
||||||
self.lnworker = None
|
self.lnworker = None
|
||||||
except TaskTimeout:
|
|
||||||
pass
|
|
||||||
finally: # even if we get cancelled
|
finally: # even if we get cancelled
|
||||||
if any([ks.is_requesting_to_be_rewritten_to_wallet_file for ks in self.get_keystores()]):
|
if any([ks.is_requesting_to_be_rewritten_to_wallet_file for ks in self.get_keystores()]):
|
||||||
self.save_keystore()
|
self.save_keystore()
|
||||||
|
|||||||
Reference in New Issue
Block a user