Created
October 5, 2018 17:16
-
-
Save norbinsh/180b12115e580fecd1818b2e9e8efd0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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