Skip to content

Commit

Permalink
Update questions.md (#13)
Browse files Browse the repository at this point in the history
update Что такое async/await, для чего они нужны и как их использовать
  • Loading branch information
warmsnow17 authored Feb 21, 2024
1 parent 345d531 commit 0b40521
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1437,16 +1437,17 @@ 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.get(url)
data = await response.text()
print('{}: {} bytes: {}'.format(url, len(data), data))
return data
async with aiohttp.ClientSession() as session:
print('Starting {}'.format(url))
async with session.get(url) as response:
data = await response.text()
print('{}: {} bytes: {}'.format(url, len(data), data))
return data

futures = [call_url(url) for url in urls]

loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(futures))
loop.run_until_complete(asyncio.gather(*futures))
```

Программа состоит из метода async. Во время выполнения он возвращает сопрограмму, которая затем находится в ожидании.
Expand Down

0 comments on commit 0b40521

Please sign in to comment.