From ca44dd696f129d3e835131306a732a9735f2259f Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Mon, 8 Apr 2024 19:49:19 -0400 Subject: [PATCH] feat: load strats in subthread to unblock loop (#704) --- yearn/v2/vaults.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/yearn/v2/vaults.py b/yearn/v2/vaults.py index 014c36716..917095bdb 100644 --- a/yearn/v2/vaults.py +++ b/yearn/v2/vaults.py @@ -251,6 +251,7 @@ def process_events(self, events): async def _unpack_results(self, results): results, strategy_descs, price = results + strategies = await run_in_thread(getattr, self, 'strategies') return await run_in_subprocess( _unpack_results, self.vault.address, @@ -260,15 +261,15 @@ async def _unpack_results(self, results): self.scale, price, # must be picklable. - [strategy.unique_name for strategy in self.strategies], + [strategy.unique_name for strategy in strategies], strategy_descs, ) async def describe(self, block=None): - await run_in_thread(self.load_strategies) + strategies = await run_in_thread(getattr, self, 'strategies') results = await asyncio.gather( fetch_multicall_async(*[[self.vault, view] for view in self._views], block=block), - asyncio.gather(*[strategy.describe(block=block) for strategy in self.strategies]), + asyncio.gather(*[strategy.describe(block=block) for strategy in strategies]), get_price_return_exceptions(self.token, block=block) ) return await self._unpack_results(results)