1
0

submarine_swaps: define main_loop, with async with taskgroup

rm unneeded @ignore_exception wrapper in lnworker and network
This commit is contained in:
ThomasV
2024-01-10 17:15:18 +01:00
parent 65210d03ac
commit 178a03129f
3 changed files with 11 additions and 4 deletions

View File

@@ -309,7 +309,6 @@ class LNWorker(Logger, EventListener, NetworkRetryManager[LNPeerAddr]):
except OSError as e:
self.logger.error(f"cannot listen for lightning p2p. error: {e!r}")
@ignore_exceptions # don't kill outer taskgroup
async def main_loop(self):
self.logger.info("starting taskgroup.")
try:

View File

@@ -207,8 +207,17 @@ class SwapManager(Logger):
self.add_lnwatcher_callback(swap)
self.taskgroup = OldTaskGroup()
coro = self.pay_pending_invoices()
asyncio.run_coroutine_threadsafe(self.taskgroup.spawn(coro), self.network.asyncio_loop)
asyncio.run_coroutine_threadsafe(self.main_loop(), self.network.asyncio_loop)
async def main_loop(self):
self.logger.info("starting taskgroup.")
try:
async with self.taskgroup as group:
await group.spawn(self.pay_pending_invoices())
except Exception as e:
self.logger.exception("taskgroup died.")
finally:
self.logger.info("taskgroup stopped.")
async def pay_invoice(self, key):
self.logger.info(f'trying to pay invoice {key}')

View File

@@ -452,7 +452,6 @@ class Abstract_Wallet(ABC, Logger, EventListener):
def _init_lnworker(self):
self.lnworker = None
@ignore_exceptions # don't kill outer taskgroup
async def main_loop(self):
self.logger.info("starting taskgroup.")
try: