-
-
Save nhumrich/933445f9de156b02950f3dacdd3ba9bb to your computer and use it in GitHub Desktop.
async blog example for async/await
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 | |
urls = ['http://www.google.com', 'http://www.yandex.ru', 'http://www.python.org'] | |
async def call_url(url): | |
print('Starting {}'.format(url)) | |
response = await aiohttp.ClientSession().get(url) | |
data = await response.text() | |
print('{}: {} bytes: {}'.format(url, len(data), data)) | |
return data | |
futures = [call_url(url) for url in urls] | |
asyncio.run(asyncio.wait(futures)) |
Sorry about the late comment. Aiohttp has since removed this method. I will need to update the example.
Updated
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aiohttp.get doesnt exist (python version maybe). Using aiohttp.request('GET', url) instead.
But further, I am getting
while running this on python 3.6. Any ideas ?