Does timeout=None work on httpx.AsyncClient.stream? #2055
-
I am trying to follow the documentation on timeout configuration https://www.python-httpx.org/advanced/#timeout-configuration
I have also tried yet none of these have prevented me from getting Do I have the wrong syntax? Is timeout configuration not currently available for async streaming? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Can you show me how to replicate this? I'm trying to see the issue you're describing. Here's a simple ASGI app... import time
async def app(scope, receive, send):
assert scope['type'] == 'http'
await send({
'type': 'http.response.start',
'status': 200,
'headers': [
[b'content-type', b'text/plain'],
],
})
await send({
'type': 'http.response.body',
'body': b'Hello, ',
'more_body': True
})
time.sleep(100)
await send({
'type': 'http.response.body',
'body': b'world',
}) Which I'm running with $ uvicorn app:app
INFO: Started server process [2329]
INFO: Waiting for application startup.
INFO: ASGI 'lifespan' protocol appears unsupported.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) And then making a request using import httpx
import asyncio
async def main():
timeout = httpx.Timeout(connect=None, read=None, write=None, pool=None)
async with httpx.AsyncClient(timeout=timeout) as client:
async with client.stream('GET', url="http://127.0.0.1:8000") as response:
if response.status_code == 200:
async for line in response.aiter_lines():
print(line)
asyncio.run(main()) When I run this, it shows exactly the behaviour I'd expect - it waits for 100 seconds before printing the response text. The timeout is also disabled if I use the more simple If I switch to Are you able to point me at a URL which I can use to replicate the behaviour you're describing, or are you able to demonstrate it to me with a simple WSGI or ASGI demo similar to the one I've showed above? |
Beta Was this translation helpful? Give feedback.
-
@tomchristie This seems to be happening for us as well. We're using This is the util that sends our requests
and based on some preprocessing, we send the response back as a stream
Any idea why this could be happening ? |
Beta Was this translation helpful? Give feedback.
-
type of timeout is a union ,details are as follows: |
Beta Was this translation helpful? Give feedback.
Can you show me how to replicate this?
I'm trying to see the issue you're describing. Here's a simple ASGI app...
Which I'm running with
uvicorn
...$ uvicorn app:app INFO: Started server process [2329] INFO: Waiting …