Closed choesy closed 4 months ago
aiohttp's client timeout settings are actually set via passing values into a separate object, with a slightly more complex data structure and so passing just an int to it isn't likely to do anything. Also, the default timeout is 5 and I think the value are rounded because the timeout is set on the event loop level. The other caveat is that because the timeout is set on the event loop level for the client, it's going to be off by a little depending on your environment, and lower the setting the more off it may be unless it's None.
Try running this modified version of your code, although the timeout (default is 300, since it is a timeout for the entire event loop) is likely too short anyway.
rom web3 import AsyncWeb3
import asyncio
from aiohttp import ClientTimeout
from time import time
timeout = ClientTimeout(total=5)
w3=AsyncWeb3(AsyncWeb3.AsyncHTTPProvider('https://rpc.ankr.com/arbitrum',request_kwargs={'timeout':timeout}))
async def get_logs():
start=time()
logs = await w3.eth.get_logs({
'fromBlock': hex(20000000),
'toBlock': hex(20000000+2000),
'topics': ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef']
})
print("n_logs:",len(logs))
print("time taken:",time()-start)
Thank you for explaining it :)
What happened?
When i am using AsyncWeb3 with AsyncHttpProvider, i set request_kwargs={"timeout":2} like in the docs. It does not always raise a timeout error as it should. Sometimes it raises error after 9-10 seconds, and sometimes it doesn't even raise the error and i get back results despite almost 9 seconds passing by. That is more that 4 times the amount of set timeout.
Code that produced the error
Full error output
Fill this section in if you know how this could or should be fixed
No response
web3 Version
6.19.0
Python Version
3.11.9
Operating System
linux
Output from
pip freeze