Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2644

Short tasks are not cancelled

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • 6.7.1, 6.8.0
    • 6.6.2
    • QtAsyncio
    • None
    • Python 3.12.0
      PySide6 6.6.2
    • Windows
    • 94c214287 (dev), 9de4dee2f (dev), a48ff4086 (6.7), 6bcacd5b8 (6.7), d1e400c62 (dev), c16a7e9b9 (6.7)

    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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            adherrma Adrian Herrmann (Inactive)
            damienb damienb
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes