-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Extend StreamResponse documentation #2283
Comments
Does #2257 satisfy your needs? |
I think my case is not discovered in this version. Also I saw this:
This is not happen in my case. Maybe I missed an option which enables this behavior or callback fired on request finalization.
|
Anyway I have managed to detect when connection is interrupted by client. from aiohttp import web
async def infinite_stream(request):
stream = web.StreamResponse()
await stream.prepare(request)
while True:
if request.transport.is_closing(): # <=== This line does the job
break
await stream.write(b'Hello Aiohttp!')
await stream.write_eof()
return stream
def main():
app = web.Application()
app.router.add_get('/infinite-stream', infinite_stream)
web.run_app(app, host='127.0.0.1', port=8080)
if __name__ == '__main__':
main() |
I suggest catching an exception instead of checking transport property: in future the transport might change behavior, HTTP/2 provides new abstraction levels and request/response pair is coupled with a HTTP/2 stream, not the whole connection. Anyway, if you do think the docs should contain a suggestion for your test case -- please feel free to make a Pull Request. |
I understand this and agree, but this exception is not raised in my case. It should be raised out of await
I think this is possible when proper solution will be found. |
I appreciate any help but frankly speaking the issue is not in my priority list. |
Wish you luck there.
I have used |
I think, here is what happen.
I am not sure if we can solve this without changing asyncio itself. |
@ttm56p just curious: are its HTTPS streams? |
Closing the issue after a year of inactivity |
Long story short
I need to stream content from given endpoint read from other source.
For that purpose I'm leveraging
aiohttp.web.StreamResponse
class.Streaming work well, but can't be finalized when stream is closed from client side.
Documentation does not have example how to handle case - when client interrupted the stream.
I have found
StreamResponse.task
field. But it not seems to be usable for this purpose.So I'm asking aiohttp team to extend documentation and show how to deal with this.
Expected behaviour
Actual behaviour
Steps to reproduce
Snippet
Command to send request
Your environment
Ubuntu 17.04, Proxy are not used, Python 3.6, aiohttp 2.2.5, pip 9.0.1
The text was updated successfully, but these errors were encountered: