From 4c4b81b3fcea78b85acc77deac43899f658b05fa Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Sat, 3 Feb 2024 19:35:55 -0500 Subject: [PATCH] fix: semaphore (#95) * fix: version * fix: semaphore value * chore: bump version to 0.8.2 * fix: "attached to a different loop" edge case --- multicall/utils.py | 13 +++++++++---- pyproject.toml | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/multicall/utils.py b/multicall/utils.py index 122bb5bb..56c2e9c4 100644 --- a/multicall/utils.py +++ b/multicall/utils.py @@ -10,8 +10,8 @@ from web3.eth import AsyncEth from web3.providers.async_base import AsyncBaseProvider -from multicall.constants import (AIOHTTP_TIMEOUT, NO_STATE_OVERRIDE, - NUM_PROCESSES) +from multicall.constants import (AIOHTTP_TIMEOUT, ASYNC_SEMAPHORE, + NO_STATE_OVERRIDE, NUM_PROCESSES) chainids: Dict[Web3,int] = {} @@ -97,6 +97,11 @@ def state_override_supported(w3: Web3) -> bool: return False return True -@lru_cache(maxsize=1) def _get_semaphore() -> asyncio.Semaphore: - return asyncio.Semaphore() \ No newline at end of file + 'Returns a `Semaphore` attached to the current event loop' + return __get_semaphore(asyncio.get_event_loop()) + +@lru_cache(maxsize=1) +def __get_semaphore(loop: asyncio.BaseEventLoop) -> asyncio.Semaphore: + 'This prevents an "attached to a different loop" edge case if the event loop is changed during your script run' + return asyncio.Semaphore(ASYNC_SEMAPHORE) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 7d1b9070..dd1a4c4c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "multicall" -version = "0.8.0" +version = "0.8.2" description = "aggregate results from multiple ethereum contract calls" authors = ["banteg"]