1
0

some clean-ups now that we require python 3.8

In particular, asyncio.CancelledError no longer inherits Exception (it inherits BaseException directly)
This commit is contained in:
SomberNight
2022-02-08 12:56:02 +01:00
parent dd2f8541b7
commit 3f3212e94d
7 changed files with 3 additions and 20 deletions

View File

@@ -505,8 +505,6 @@ class Daemon(Logger):
async with self.taskgroup as group:
[await group.spawn(job) for job in jobs]
await group.spawn(asyncio.Event().wait) # run forever (until cancel)
except asyncio.CancelledError:
raise
except Exception as e:
self.logger.exception("taskgroup died.")
util.send_exception_to_crash_reporter(e)

View File

@@ -80,9 +80,6 @@ class ExchangeBase(Logger):
self.logger.info(f"getting fx quotes for {ccy}")
self.quotes = await self.get_rates(ccy)
self.logger.info("received fx quotes")
except asyncio.CancelledError:
# CancelledError must be passed-through for cancellation to work
raise
except aiohttp.ClientError as e:
self.logger.info(f"failed fx quotes: {repr(e)}")
self.quotes = {}

View File

@@ -380,8 +380,7 @@ class Interface(Logger):
async def spawn_task():
task = await self.network.taskgroup.spawn(self.run())
if sys.version_info >= (3, 8):
task.set_name(f"interface::{str(server)}")
task.set_name(f"interface::{str(server)}")
asyncio.run_coroutine_threadsafe(spawn_task(), self.network.asyncio_loop)
@property

View File

@@ -123,8 +123,6 @@ class LNTransportBase:
break
try:
s = await self.reader.read(2**10)
except asyncio.CancelledError:
raise
except Exception:
s = None
if not s:

View File

@@ -266,8 +266,6 @@ class LNWorker(Logger, NetworkRetryManager[LNPeerAddr]):
try:
async with self.taskgroup as group:
await group.spawn(self._maintain_connectivity())
except asyncio.CancelledError:
raise
except Exception as e:
self.logger.exception("taskgroup died.")
finally:

View File

@@ -1202,8 +1202,6 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
async with taskgroup as group:
await group.spawn(self._maintain_sessions())
[await group.spawn(job) for job in self._jobs]
except asyncio.CancelledError:
raise
except Exception as e:
self.logger.exception("taskgroup died.")
finally:

View File

@@ -1178,9 +1178,6 @@ def ignore_exceptions(func):
async def wrapper(*args, **kwargs):
try:
return await func(*args, **kwargs)
except asyncio.CancelledError:
# note: with python 3.8, CancelledError no longer inherits Exception, so this catch is redundant
raise
except Exception as e:
pass
return wrapper
@@ -1669,10 +1666,8 @@ class nullcontext:
async def __aexit__(self, *excinfo):
pass
def get_running_loop():
"""Mimics _get_running_loop convenient functionality for sanity checks on all python versions"""
if sys.version_info < (3, 7):
return asyncio._get_running_loop()
def get_running_loop() -> Optional[asyncio.AbstractEventLoop]:
try:
return asyncio.get_running_loop()
except RuntimeError: