File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -1437,16 +1437,17 @@ import aiohttp
14371437urls = [' http://www.google.com' , ' http://www.yandex.ru' , ' http://www.python.org' ]
14381438
14391439async def call_url (url ):
1440- print (' Starting {} ' .format(url))
1441- response = await aiohttp.get(url)
1442- data = await response.text()
1443- print (' {} : {} bytes: {} ' .format(url, len (data), data))
1444- return data
1440+ async with aiohttp.ClientSession() as session:
1441+ print (' Starting {} ' .format(url))
1442+ async with session.get(url) as response:
1443+ data = await response.text()
1444+ print (' {} : {} bytes: {} ' .format(url, len (data), data))
1445+ return data
14451446
14461447futures = [call_https://github.com/url(url) for url in urls]
14471448
14481449loop = asyncio.get_event_loop()
1449- loop.run_until_complete(asyncio.wait( futures))
1450+ loop.run_until_complete(asyncio.gather( * futures))
14501451```
14511452
14521453Программа состоит из метода async. Во время выполнения он возвращает сопрограмму, которая затем находится в ожидании.
You can’t perform that action at this time.
0 commit comments