Skip to content

Instantly share code, notes, and snippets.

@norbinsh
Created October 5, 2018 17:16
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 norbinsh/180b12115e580fecd1818b2e9e8efd0b to your computer and use it in GitHub Desktop.
Save norbinsh/180b12115e580fecd1818b2e9e8efd0b to your computer and use it in GitHub Desktop.
import asyncio
import aiohttp
async def get_http(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
return await response.text()
def main():
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
async def run():
q = asyncio.Queue()
with open("urls", "r") as rf:
urls = rf.read().splitlines()
for url in urls:
await q.put((asyncio.create_task(get_http(url))))
while q.qsize() > 0:
t = await q.get()
resp = await t
print("Done", resp)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment