I actually got it too work though I do see that if I run two jobs of the same code in parallel the async execution time slows down. Do the number of workers of the cluster on which the parallel jobs are run effect the execution time of async calls of the jobs?
Here is the code that I got to run:
# Asynchronous function to fetch data from a given URL using aiohttp
async def fetch_data(session, url😞
async with session.get(url) as response:
return await response.json()
# Asynchronous main function
async def get_url_data(input_args😞
# List of URLs to fetch data from
urls = [get_api_url(input_arg) for input_arg in input_args]
headers = {'X-API-KEY': "<API_KEY>"}
# Create an aiohttp ClientSession for making asynchronous HTTP requests
async with aiohttp.ClientSession(headers=headers) as session:
# Create a list of tasks, where each task is a call to 'fetch_data' with a specific URL
tasks = [fetch_data(session, url) for url in urls]
# Use 'asyncio.gather()' to run the tasks concurrently and gather their results
results = await asyncio.gather(*tasks, return_exceptions=False)
# Print the results obtained from fetching data from each URL
return results