Details
Description
It seems that sometimes tasks are not cancelled as expected.
In the following example, if the loop sleep is long enough, the error raised in will_raise causes the loop to be cancelled by the task group.
The error is eventually raised by QtAsyncio.run, which is the expected behavior.
However, if the loop sleep is smaller than about 1e-3, the loop is never cancelled and the script runs until aborted.
import asyncio from PySide6 import QtAsyncio async def will_raise(): raise RuntimeError("error") async def loop(): while True: # If the delay is too short, the task is never cancelled. await asyncio.sleep(1e-3) # The error seems to occur for short tasks, # It also occurs when replacing asyncio.sleep with: # await asyncio.to_thread(lambda: None) async def main(): async with asyncio.TaskGroup() as tg: tg.create_task(loop()) tg.create_task(will_raise()) QtAsyncio.run(main(), keep_running=False)