-
-
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
Counting bytes in a forwarded stream #3598
Labels
Comments
|
Hi there, Thanks for that, here is the full example but I can't seem to get anything other than zero out of wrapper._counter. Is wrapper deep-copied during session.post? import aiohttp
import asyncio
class Wrapper:
def __init__(self, content):
self._content = content
self._counter = 0
self._iter = None
def __aiter__(self):
self._iter = self._content.__aiter__()
return self # return self, not self._iter
async def __anext__(self):
chunk = await self._iter.__anext__()
self._counter += len(chunk)
return chunk
async def main():
session=aiohttp.ClientSession()
resp = await session.get('http://python.org')
wrapper = Wrapper(resp.content)
await session.post('http://httpbin.org/post', data=wrapper)
print(wrapper._counter)
loop = asyncio.get_event_loop()
loop.run_until_complete(main()) |
Sorry, I've made a mistake in |
Thanks for your help on this, much appreciated! |
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there,
In the documentation I see that I can open a connection from one source and pass the content to another stream as follows:
resp = await session.get('http://python.org')
await session.post('http://httpbin.org/post', data=resp.content)
In my implementation of this I will be forwarding streams of potentially very large files with unknown length. I need to be able to count the bytes that is transferred in resp.content without dumping resp.content to a local file. How can I do this?
Thankyou in advance!
The text was updated successfully, but these errors were encountered: