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)
Attachments
For Gerrit Dashboard: PYSIDE-2644 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
556397,2 | QtAsyncio: Round handle timeouts | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
556398,2 | QtAsyncio: Fix tasks with loop not cancelling | dev | pyside/pyside-setup | Status: MERGED | -1 | 0 |
556629,2 | QtAsyncio: Round handle timeouts | 6.7 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
556630,2 | QtAsyncio: Fix tasks with loop not cancelling | 6.7 | pyside/pyside-setup | Status: MERGED | -1 | 0 |
577007,4 | QtAsyncio: Add clarifying comments | dev | pyside/pyside-setup | Status: MERGED | -1 | 0 |
577741,2 | QtAsyncio: Add clarifying comments | 6.7 | pyside/pyside-setup | Status: MERGED | +2 | 0 |