Python 3.7.4 and 3.10.6 asyncio creating multiple tasks in VS Code debug call stack

61 Views Asked by At

When using asyncio and aiohttp, faced this issue and was wondering if it was an occurance limited to VSC only?

This one keeps leaving residues from the previous loops.

while True:
     loop.run_until_complete(get_data())

This runs without any residual tasks.

while True:
     asyncio.run(get_data())

session = aiohttp.ClientSession()

async def fetch(url, params=None):
     async with semaphore:
         async with session.get(url, params=params) as response:
             return await response.json()

I tried moving the while loop inside the called method itself but still the same result. Also tried using semaphores with no better luck. I was trying to manage multiple rest api call methods using aiohttp from within a single loop but with this happening, guess I am stuck with having to use asyncio.run separately for each api related method. So the only way to avoid this right now is to keep closing and reopening separate loops? Could this possibly be a VSC related issue?


Edit: Tried something with Python 3.10.6 and VSCodium. I don't know if it's because this one shows tasks/loops instead of threadpool here but the same issue is not replicated. The increment issue still persists when using Python 3.10.6 with VS Code. So could this be either 1) VSC issue as suspected or 2) just that the call stacks are being treated different between the two IDEs?

while True:
     asyncio.run(get_data())

enter image description here

Another thing to note is that the ThreadPoolExecutor stacking when using VSC, stops exactly at the 20th stack: ThreadPoolExecutor-0_19. Then no more increments and no crashes.

enter image description here

0

There are 0 best solutions below