Skip to content

Commit

Permalink
fix: try except _futs.remove (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Apr 23, 2023
1 parent ba497d6 commit 71e79b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 11 additions & 2 deletions dank_mids/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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.')

8 changes: 6 additions & 2 deletions dank_mids/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 71e79b2

Please sign in to comment.