I have a function that sends 2 different requests. I need to call this function with different parameters 20 times.
I would like to run the functions concurrently (different arguments) to spare some time between request and response.
This is a very simplified function:
async def get_data(url):
return requests.get(url)
And this is how I call it:
loop = asyncio.get_event_loop()
tasks = [asyncio.ensure_future(get_data(url)) for url in websites.split('\n')]
group = asyncio.gather(*tasks)
results = loop.run_until_complete(group)
print(results)
loop.close()
The problem is that it runs sequentially instead of concurrently.
It's obvious that I'm missing something. Do you know what to do?