Sep-18-2020, 10:06 AM
I'm looking for transform the following code into parallel execution :
Thanks
urls = ['http://example1.org', 'http://example2.org', '...']
def getResults(urls):
results = {}
for url in urls:
results[url] = getResult(url)
return results
def getResult(url):
return get(url).json()Here is what I've tried:urls = ['http://example1.org', 'http://example2.org', '...']
def getResults(urls):
return asyncio.gather((getResult(url)) for url in urls)
async def getResult(url):
return await get(url).json()Am I on the right track ? What's the correct way to use async/await with python 3?Thanks
