I tried to read https://hackernoon.com/asynchronous-python-45df84b82434.
It's about asynchronous python and I tried the code from this, but I'm getting a weird Error.
The code is:
`
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))
When I try to run it says:
Traceback (most recent call last):
File "test.py", line 15, in <module>
asyncio.run(asyncio.wait(futures))
AttributeError: module 'asyncio' has no attribute 'run'
sys:1: RuntimeWarning: coroutine 'call_url' was never awaited
I dont have any files named ayncio and I have proof:
>>> asyncio
<module 'asyncio' from '/usr/lib/python3.6/asyncio/__init__.py'>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…