mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
python 3.8: adapt to breaking changes re asyncio.CancelledError
(and TimeoutError) closes #5798
This commit is contained in:
parent
fa9b997c70
commit
308517d473
5 changed files with 13 additions and 7 deletions
|
@ -15,6 +15,7 @@ from datetime import datetime, timezone
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import concurrent
|
import concurrent
|
||||||
|
from concurrent import futures
|
||||||
|
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
import dns.exception
|
import dns.exception
|
||||||
|
|
|
@ -35,6 +35,8 @@ import ipaddress
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import NamedTuple, Optional, Sequence, List, Dict, Tuple, TYPE_CHECKING
|
from typing import NamedTuple, Optional, Sequence, List, Dict, Tuple, TYPE_CHECKING
|
||||||
import traceback
|
import traceback
|
||||||
|
import concurrent
|
||||||
|
from concurrent import futures
|
||||||
|
|
||||||
import dns
|
import dns
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
|
@ -1204,7 +1206,7 @@ class Network(Logger):
|
||||||
fut = asyncio.run_coroutine_threadsafe(self._stop(full_shutdown=True), self.asyncio_loop)
|
fut = asyncio.run_coroutine_threadsafe(self._stop(full_shutdown=True), self.asyncio_loop)
|
||||||
try:
|
try:
|
||||||
fut.result(timeout=2)
|
fut.result(timeout=2)
|
||||||
except (asyncio.TimeoutError, asyncio.CancelledError): pass
|
except (concurrent.futures.TimeoutError, concurrent.futures.CancelledError): pass
|
||||||
|
|
||||||
async def _ensure_there_is_a_main_interface(self):
|
async def _ensure_there_is_a_main_interface(self):
|
||||||
if self.is_connected():
|
if self.is_connected():
|
||||||
|
|
|
@ -5,6 +5,8 @@ import os
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import logging
|
import logging
|
||||||
|
import concurrent
|
||||||
|
from concurrent import futures
|
||||||
|
|
||||||
from electrum.network import Network
|
from electrum.network import Network
|
||||||
from electrum.ecc import ECPrivkey
|
from electrum.ecc import ECPrivkey
|
||||||
|
@ -236,7 +238,7 @@ class TestPeer(ElectrumTestCase):
|
||||||
gath = asyncio.gather(pay(), p1._message_loop(), p2._message_loop())
|
gath = asyncio.gather(pay(), p1._message_loop(), p2._message_loop())
|
||||||
async def f():
|
async def f():
|
||||||
await gath
|
await gath
|
||||||
with self.assertRaises(asyncio.CancelledError):
|
with self.assertRaises(concurrent.futures.CancelledError):
|
||||||
run(f())
|
run(f())
|
||||||
|
|
||||||
def test_channel_usage_after_closing(self):
|
def test_channel_usage_after_closing(self):
|
||||||
|
|
|
@ -38,7 +38,7 @@ class TestLNTransport(ElectrumTestCase):
|
||||||
asyncio.get_event_loop().run_until_complete(transport.handshake(epriv=e_priv))
|
asyncio.get_event_loop().run_until_complete(transport.handshake(epriv=e_priv))
|
||||||
|
|
||||||
def test_loop(self):
|
def test_loop(self):
|
||||||
l = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
responder_shaked = asyncio.Event()
|
responder_shaked = asyncio.Event()
|
||||||
server_shaked = asyncio.Event()
|
server_shaked = asyncio.Event()
|
||||||
responder_key = ECPrivkey.generate_random_key()
|
responder_key = ECPrivkey.generate_random_key()
|
||||||
|
@ -50,7 +50,7 @@ class TestLNTransport(ElectrumTestCase):
|
||||||
self.assertEqual(await t.read_messages().__anext__(), b'hello from client')
|
self.assertEqual(await t.read_messages().__anext__(), b'hello from client')
|
||||||
responder_shaked.set()
|
responder_shaked.set()
|
||||||
server_future = asyncio.ensure_future(asyncio.start_server(cb, '127.0.0.1', 42898))
|
server_future = asyncio.ensure_future(asyncio.start_server(cb, '127.0.0.1', 42898))
|
||||||
l.run_until_complete(server_future)
|
loop.run_until_complete(server_future)
|
||||||
async def connect():
|
async def connect():
|
||||||
peer_addr = LNPeerAddr('127.0.0.1', 42898, responder_key.get_public_key_bytes())
|
peer_addr = LNPeerAddr('127.0.0.1', 42898, responder_key.get_public_key_bytes())
|
||||||
t = LNTransport(initiator_key.get_secret_bytes(), peer_addr)
|
t = LNTransport(initiator_key.get_secret_bytes(), peer_addr)
|
||||||
|
@ -59,6 +59,6 @@ class TestLNTransport(ElectrumTestCase):
|
||||||
self.assertEqual(await t.read_messages().__anext__(), b'hello from server')
|
self.assertEqual(await t.read_messages().__anext__(), b'hello from server')
|
||||||
server_shaked.set()
|
server_shaked.set()
|
||||||
|
|
||||||
asyncio.ensure_future(connect())
|
connect_future = asyncio.ensure_future(connect())
|
||||||
l.run_until_complete(responder_shaked.wait())
|
loop.run_until_complete(responder_shaked.wait())
|
||||||
l.run_until_complete(server_shaked.wait())
|
loop.run_until_complete(server_shaked.wait())
|
||||||
|
|
|
@ -1020,6 +1020,7 @@ def ignore_exceptions(func):
|
||||||
try:
|
try:
|
||||||
return await func(*args, **kwargs)
|
return await func(*args, **kwargs)
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
|
# note: with python 3.8, CancelledError no longer inherits Exception, so this catch is redundant
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Add table
Reference in a new issue