Skip to content

Commit

Permalink
some clean-ups now that we require python 3.8
Browse files Browse the repository at this point in the history
In particular, asyncio.CancelledError no longer inherits Exception (it inherits BaseException directly)
  • Loading branch information
SomberNight committed Feb 8, 2022
1 parent eea4d31 commit 259c1fe
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 20 deletions.
2 changes: 0 additions & 2 deletions electrum/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,6 @@ async def _run(self, jobs: Iterable = None):
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)
Expand Down
3 changes: 0 additions & 3 deletions electrum/exchange_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ async def update_safe(self, ccy):
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 = {}
Expand Down
3 changes: 1 addition & 2 deletions electrum/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ def __init__(self, *, network: 'Network', server: ServerAddr, proxy: Optional[di

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
Expand Down
2 changes: 0 additions & 2 deletions electrum/lntransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ async def read_messages(self):
break
try:
s = await self.reader.read(2**10)
except asyncio.CancelledError:
raise
except Exception:
s = None
if not s:
Expand Down
2 changes: 0 additions & 2 deletions electrum/lnworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ async def main_loop(self):
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:
Expand Down
2 changes: 0 additions & 2 deletions electrum/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,8 +1202,6 @@ async def main():
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:
Expand Down
9 changes: 2 additions & 7 deletions electrum/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1669,10 +1666,8 @@ async def __aenter__(self):
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:
Expand Down

0 comments on commit 259c1fe

Please sign in to comment.