With this asyncio code, my tutor says that all coroutines (here the 50 "fetch_page") first stop at the first async with and wait, then all of them resume from there and stop at the second async with, then finally all of them all return.
import aiohttp import asyncio async def fetch_page(url): print(1) async with aiohttp.ClientSession() as session: print(2) async with session.get(url) as response: print(3) return response.status loop = asyncio.get_event_loop() tasks = [fetch_page('http://google.com') for i in range(50)] loop.run_until_complete(asyncio.gather(*tasks)) I'm debugging this, and I must say he's wrong. While debugging, I see all coroutines going sequentially to the second async with, where they all stop. Then once all the 50 coroutines resumes, they do the session.get(url) and return.
But why not all of the couroutines stop at the first async with ?
Print output : "1 2 1 2 1 2 ... 3 3 3 ...", instead of "1 1 1 ... 2 2 2 ... 3 3 3 ..."