banteg / multicall.py

aggregate results of multiple smart contract calls into one
MIT License
246 stars 106 forks source link

Stucked at _get_semaphore() while using python to execute the script directly #91

Closed r-hou closed 5 months ago

r-hou commented 11 months ago

I am trying to use this package to get the balance of ETH from multiple addresses, below is my code

node_url = 'xxxx'
w3 = Web3(Web3.HTTPProvider(node_url))
addresses = ["0xxxxx", "0xxxxx"]
def from_wei(status, value):
    print(status, value)
    return value / 1e18
multi = Multicall([
    Call(multi_call_address, ['getEthBalance(address)(uint256)', addresses[0]], [(addresses[0], from_wei)]),
    Call(multi_call_address, ['getEthBalance(address)(uint256)', addresses[1]], [(addresses[1], from_wei)]),
], require_success=False, _w3=w3)
results = multi()
print(results)

then I run the script from console,

python test.py

however, the code doesn't output anything and hang, I try to debug it and find the code gets stucked at

@lru_cache(maxsize=1)
def _get_semaphore() -> asyncio.Semaphore:
    return asyncio.Semaphore()

interestingly, the code can run correctly if I remove the decorator @lru_cache(maxsize=1), may I know how to run it corretly without removing the decorator? Thanks!

BobTheBuidler commented 5 months ago

fixed in #95, closing this issue