Skip to content

Commit

Permalink
fix: semaphore (#95)
Browse files Browse the repository at this point in the history
* fix: version

* fix: semaphore value

* chore: bump version to 0.8.2

* fix: "attached to a different loop" edge case
  • Loading branch information
BobTheBuidler authored Feb 4, 2024
1 parent 9117c55 commit 4c4b81b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions multicall/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}

Expand Down Expand Up @@ -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()
'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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down

0 comments on commit 4c4b81b

Please sign in to comment.