-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClientSession.request unexpectedly cancels task on timeout #2286
Comments
can You use just |
That still won't let me handle the time out within |
@hellysmile FYI I updated the code snippet to include One solution would be not to catch the TimeoutError inside of |
I meet the same issues!!!!! async def ceshi(request, *args, **kwargs):
# url = "https://stackoverflow.com/jobs?med=site-ui&ref=jobs-tab"
url = 'https://api.github.com/events'
url = 'https://www.baidu.com'
try:
async with aiohttp.ClientSession(conn_timeout=5,read_timeout=10) as session:
async with session.get(url,timeout=5) as resp:
print(resp.status)
data = await resp.text()
return HTTPResponse(data)
except:
return HTTPResponse("error", status=400) |
@savvopoulos @wojunnihou I cannot reproduce:
timeout.py is the script uploaded by @savvopoulos |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
Long story short
await client.get('https://httpbin.org/delay/10', timeout=.1)
This call throws an exception on timeout, and it cancels the task it's running in.
This makes it hard to handle timeouts locally, e.g. by catching the timeout and returning an alternate value.
It would at least be worth documenting this behavior.
Expected behaviour
I would have liked/expected the sample below to print:
Caught exception! api_req was able to handle timeout.
Actual behaviour
Caught exception! aiohttp cancelled us
Steps to reproduce
Your environment
python 3.6.2
on osxThe text was updated successfully, but these errors were encountered: