Answer the question
In order to leave comments, you need to log in
How does asyncio parallelize tasks?
Let's say that 3 http requests are made using the asyncio module.
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.get(url)
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))
Answer the question
In order to leave comments, you need to log in
puts each of them in a separate thread
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question