I have to keep my application compatible with Python 2 and 3 at the same time.
I have some code like the following that I want to be able to asynchronously call a function and then wait for all my futures to be resolved.
Code:
import requests
# This would return a future
def get_xhr(url):
return requests.get('https://www.{}.com'.format(url))
# This would return an array of futures
def get_search_engines():
urls = ['google', 'yahoo', 'bing']
return [get_xhr(url) for url in urls]
# Here I want to wait for all the futures to be resolved
get_search_engines()
print('All requests are done')
Asyncio async/await seems only compatible with Python 3.
What is the best way to be able to run functions async thats compatible for both python 2/3?