Sep-20-2020, 06:35 PM
1.) Yes it's possible, you can just call the
2.) Let's say your new
3.)
Regarding an example for aiohttp, there is a really simple one in the link I sent you:
asyncio.run
in getResults
but you will have to move the asyncio.gather
to a new coroutine2.) Let's say your new
getResult
function will look something like this:async def get_url_result(url): response = await asynchronous_get_request(url) # not an actual working code return responsethen response will be a some kind of
Response
object which will have url
attribute and the actual response that you can then use to update your dictionary with3.)
requests
is a blocking library, which would make the whole point of using asyncio in your case pointless. There is actually no "thread split", asyncio runs only in one thread and it runs concurrently and not in parallel. What happens when you use non-blocking call in this case, is that when a request is made, while it waits for response, it gives back control to the event loop, so other coroutines that are scheduled on it, can be run. There is a nice explanation on real python -> https://realpython.com/async-io-python/Regarding an example for aiohttp, there is a really simple one in the link I sent you:
async with aiohttp.ClientSession() as session: async with session.get('http://httpbin.org/get') as resp: print(resp.status) print(await resp.text())It would be good if you'll try to do it on your own, post your experiments and I'll help