|
|
@ -32,7 +32,7 @@ import socket |
|
|
|
import json |
|
|
|
import sys |
|
|
|
import asyncio |
|
|
|
from typing import NamedTuple, Optional, Sequence, List, Dict, Tuple, TYPE_CHECKING, Iterable, Set, Any |
|
|
|
from typing import NamedTuple, Optional, Sequence, List, Dict, Tuple, TYPE_CHECKING, Iterable, Set, Any, TypeVar |
|
|
|
import traceback |
|
|
|
import concurrent |
|
|
|
from concurrent import futures |
|
|
@ -64,6 +64,8 @@ from .i18n import _ |
|
|
|
from .logging import get_logger, Logger |
|
|
|
|
|
|
|
if TYPE_CHECKING: |
|
|
|
from collections.abc import Coroutine |
|
|
|
|
|
|
|
from .channel_db import ChannelDB |
|
|
|
from .lnrouter import LNPathFinder |
|
|
|
from .lnworker import LNGossip |
|
|
@ -78,6 +80,8 @@ NUM_TARGET_CONNECTED_SERVERS = 10 |
|
|
|
NUM_STICKY_SERVERS = 4 |
|
|
|
NUM_RECENT_SERVERS = 20 |
|
|
|
|
|
|
|
T = TypeVar('T') |
|
|
|
|
|
|
|
|
|
|
|
def parse_servers(result: Sequence[Tuple[str, str, List[str]]]) -> Dict[str, dict]: |
|
|
|
"""Convert servers list (from protocol method "server.peers.subscribe") into dict format. |
|
|
@ -382,7 +386,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]): |
|
|
|
self.path_finder = None |
|
|
|
|
|
|
|
@classmethod |
|
|
|
def run_from_another_thread(cls, coro, *, timeout=None): |
|
|
|
def run_from_another_thread(cls, coro: 'Coroutine[Any, Any, T]', *, timeout=None) -> T: |
|
|
|
loop = util.get_asyncio_loop() |
|
|
|
assert util.get_running_loop() != loop, 'must not be called from asyncio thread' |
|
|
|
fut = asyncio.run_coroutine_threadsafe(coro, loop) |
|
|
|