From 71e79b24820c06c678a3fcb8477c289eda035704 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Sun, 23 Apr 2023 17:49:08 -0400 Subject: [PATCH] fix: try except _futs.remove (#65) --- dank_mids/controller.py | 13 +++++++++++-- dank_mids/worker.py | 8 ++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/dank_mids/controller.py b/dank_mids/controller.py index 23d9dffc..cbeb2883 100644 --- a/dank_mids/controller.py +++ b/dank_mids/controller.py @@ -132,7 +132,11 @@ def done_callback(fut: asyncio.Future) -> None: """Notifies the controller in the event of daemon shutdown or failure.""" self._daemon_running = False if not fut.exception(): - self._futs.remove(fut) + try: + self._futs.remove(fut) + except ValueError as e: + if str(e) != "list.remove(x): x not in list": + raise fut.add_done_callback(done_callback) self._futs.append(fut) @@ -152,7 +156,12 @@ async def _exception_daemon(self) -> None: main_logger.debug(self._futs) for fut in futs: if fut.done() and not fut.exception(): - self._futs.remove(fut) + try: + self._futs.remove(fut) + except ValueError as e: + if str(e) != "list.remove(x): x not in list": + raise + await asyncio.sleep(5) main_logger.debug('exiting exception daemon.') diff --git a/dank_mids/worker.py b/dank_mids/worker.py index 23de25de..4f605f9a 100644 --- a/dank_mids/worker.py +++ b/dank_mids/worker.py @@ -78,8 +78,12 @@ def _raise_exception_in_main_thread(self, fut: asyncio.Future) -> None: if e := fut.exception(): main_logger.error(e) raise e - self.controller._futs.remove(fut) - + try: + self.controller._futs.remove(fut) + except ValueError as e: + if str(e) != "list.remove(x): x not in list": + raise + class DankBatch: """ A batch of jsonrpc batches. """ def __init__(self, worker: DankWorker, eth_calls: Multicalls, rpc_calls: JSONRPCBatch):