network.run_from_another_thread: add type hint
This commit is contained in:
@@ -32,7 +32,7 @@ import socket
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import asyncio
|
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 traceback
|
||||||
import concurrent
|
import concurrent
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
@@ -64,6 +64,8 @@ from .i18n import _
|
|||||||
from .logging import get_logger, Logger
|
from .logging import get_logger, Logger
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Coroutine
|
||||||
|
|
||||||
from .channel_db import ChannelDB
|
from .channel_db import ChannelDB
|
||||||
from .lnrouter import LNPathFinder
|
from .lnrouter import LNPathFinder
|
||||||
from .lnworker import LNGossip
|
from .lnworker import LNGossip
|
||||||
@@ -78,6 +80,8 @@ NUM_TARGET_CONNECTED_SERVERS = 10
|
|||||||
NUM_STICKY_SERVERS = 4
|
NUM_STICKY_SERVERS = 4
|
||||||
NUM_RECENT_SERVERS = 20
|
NUM_RECENT_SERVERS = 20
|
||||||
|
|
||||||
|
T = TypeVar('T')
|
||||||
|
|
||||||
|
|
||||||
def parse_servers(result: Sequence[Tuple[str, str, List[str]]]) -> Dict[str, dict]:
|
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.
|
"""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
|
self.path_finder = None
|
||||||
|
|
||||||
@classmethod
|
@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()
|
loop = util.get_asyncio_loop()
|
||||||
assert util.get_running_loop() != loop, 'must not be called from asyncio thread'
|
assert util.get_running_loop() != loop, 'must not be called from asyncio thread'
|
||||||
fut = asyncio.run_coroutine_threadsafe(coro, loop)
|
fut = asyncio.run_coroutine_threadsafe(coro, loop)
|
||||||
|
|||||||
Reference in New Issue
Block a user