Skip to content

Instantly share code, notes, and snippets.

@bmbouter
Created October 18, 2018 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmbouter/90c1eb9d0b476a0a674930aa33852b56 to your computer and use it in GitHub Desktop.
Save bmbouter/90c1eb9d0b476a0a674930aa33852b56 to your computer and use it in GitHub Desktop.
import asyncio
import aiohttp
async def download(session):
async with session.get('http://localhost:8080/') as resp:
while True:
chunk = await resp.content.read(1024)
# print(chunk)
if not chunk:
break
print('status={code}'.format(code=resp.status))
async def run():
session = aiohttp.ClientSession()
downloaders = [download(session) for i in range(2)]
await asyncio.gather(*downloaders)
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait([run()]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment