Skip to content

Commit

Permalink
feat: load strats in subthread to unblock loop
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler committed Sep 27, 2023
1 parent ef684fa commit 7575187
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions yearn/v2/vaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 7575187

Please sign in to comment.