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:
@@ -505,8 +505,6 @@ class Daemon(Logger):
|
|||||||
async with self.taskgroup as group:
|
async with self.taskgroup as group:
|
||||||
[await group.spawn(job) for job in jobs]
|
[await group.spawn(job) for job in jobs]
|
||||||
await group.spawn(asyncio.Event().wait) # run forever (until cancel)
|
await group.spawn(asyncio.Event().wait) # run forever (until cancel)
|
||||||
except asyncio.CancelledError:
|
|
||||||
raise
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.exception("taskgroup died.")
|
self.logger.exception("taskgroup died.")
|
||||||
util.send_exception_to_crash_reporter(e)
|
util.send_exception_to_crash_reporter(e)
|
||||||
|
|||||||
@@ -80,9 +80,6 @@ class ExchangeBase(Logger):
|
|||||||
self.logger.info(f"getting fx quotes for {ccy}")
|
self.logger.info(f"getting fx quotes for {ccy}")
|
||||||
self.quotes = await self.get_rates(ccy)
|
self.quotes = await self.get_rates(ccy)
|
||||||
self.logger.info("received fx quotes")
|
self.logger.info("received fx quotes")
|
||||||
except asyncio.CancelledError:
|
|
||||||
# CancelledError must be passed-through for cancellation to work
|
|
||||||
raise
|
|
||||||
except aiohttp.ClientError as e:
|
except aiohttp.ClientError as e:
|
||||||
self.logger.info(f"failed fx quotes: {repr(e)}")
|
self.logger.info(f"failed fx quotes: {repr(e)}")
|
||||||
self.quotes = {}
|
self.quotes = {}
|
||||||
|
|||||||
@@ -380,8 +380,7 @@ class Interface(Logger):
|
|||||||
|
|
||||||
async def spawn_task():
|
async def spawn_task():
|
||||||
task = await self.network.taskgroup.spawn(self.run())
|
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)
|
asyncio.run_coroutine_threadsafe(spawn_task(), self.network.asyncio_loop)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -123,8 +123,6 @@ class LNTransportBase:
|
|||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
s = await self.reader.read(2**10)
|
s = await self.reader.read(2**10)
|
||||||
except asyncio.CancelledError:
|
|
||||||
raise
|
|
||||||
except Exception:
|
except Exception:
|
||||||
s = None
|
s = None
|
||||||
if not s:
|
if not s:
|
||||||
|
|||||||
@@ -266,8 +266,6 @@ class LNWorker(Logger, NetworkRetryManager[LNPeerAddr]):
|
|||||||
try:
|
try:
|
||||||
async with self.taskgroup as group:
|
async with self.taskgroup as group:
|
||||||
await group.spawn(self._maintain_connectivity())
|
await group.spawn(self._maintain_connectivity())
|
||||||
except asyncio.CancelledError:
|
|
||||||
raise
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.exception("taskgroup died.")
|
self.logger.exception("taskgroup died.")
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -1202,8 +1202,6 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
|
|||||||
async with taskgroup as group:
|
async with taskgroup as group:
|
||||||
await group.spawn(self._maintain_sessions())
|
await group.spawn(self._maintain_sessions())
|
||||||
[await group.spawn(job) for job in self._jobs]
|
[await group.spawn(job) for job in self._jobs]
|
||||||
except asyncio.CancelledError:
|
|
||||||
raise
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.exception("taskgroup died.")
|
self.logger.exception("taskgroup died.")
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -1178,9 +1178,6 @@ def ignore_exceptions(func):
|
|||||||
async def wrapper(*args, **kwargs):
|
async def wrapper(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return await func(*args, **kwargs)
|
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:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
return wrapper
|
return wrapper
|
||||||
@@ -1669,10 +1666,8 @@ class nullcontext:
|
|||||||
async def __aexit__(self, *excinfo):
|
async def __aexit__(self, *excinfo):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_running_loop():
|
|
||||||
"""Mimics _get_running_loop convenient functionality for sanity checks on all python versions"""
|
def get_running_loop() -> Optional[asyncio.AbstractEventLoop]:
|
||||||
if sys.version_info < (3, 7):
|
|
||||||
return asyncio._get_running_loop()
|
|
||||||
try:
|
try:
|
||||||
return asyncio.get_running_loop()
|
return asyncio.get_running_loop()
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
|
|||||||
Reference in New Issue
Block a user