Browse Source

some clean-ups now that we require python 3.8

In particular, asyncio.CancelledError no longer inherits Exception (it inherits BaseException directly)
patch-4
SomberNight 3 years ago
parent
commit
3f3212e94d
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/daemon.py
  2. 3
      electrum/exchange_rate.py
  3. 3
      electrum/interface.py
  4. 2
      electrum/lntransport.py
  5. 2
      electrum/lnworker.py
  6. 2
      electrum/network.py
  7. 9
      electrum/util.py

2
electrum/daemon.py

@ -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)

3
electrum/exchange_rate.py

@ -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 = {}

3
electrum/interface.py

@ -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

2
electrum/lntransport.py

@ -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:

2
electrum/lnworker.py

@ -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:

2
electrum/network.py

@ -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:

9
electrum/util.py

@ -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:

Loading…
Cancel
Save