diff options
| -rw-r--r-- | sources/pyside6/PySide6/QtAsyncio/tasks.py | 3 | ||||
| -rw-r--r-- | sources/pyside6/tests/QtAsyncio/bug_2799.py | 30 |
2 files changed, 31 insertions, 2 deletions
diff --git a/sources/pyside6/PySide6/QtAsyncio/tasks.py b/sources/pyside6/PySide6/QtAsyncio/tasks.py index 9a5698432..34daa3b2b 100644 --- a/sources/pyside6/PySide6/QtAsyncio/tasks.py +++ b/sources/pyside6/PySide6/QtAsyncio/tasks.py @@ -26,7 +26,7 @@ class QAsyncioTask(futures.QAsyncioFuture): # The task creates a handle for its coroutine. The handle enqueues the # task's step function as its callback in the event loop. - self._handle = self._loop.call_soon(self._step, context=self._context) + self._loop.call_soon(self._step, context=self._context) # The task step function executes the coroutine until it finishes, # raises an exception or returns a future. If a future was returned, @@ -182,7 +182,6 @@ class QAsyncioTask(futures.QAsyncioFuture): return False self._cancel_count += 1 self._cancel_message = msg - self._handle.cancel() if self._future_to_await is not None: # A task that is awaiting a future must also cancel this future in # order for the cancellation to be successful. diff --git a/sources/pyside6/tests/QtAsyncio/bug_2799.py b/sources/pyside6/tests/QtAsyncio/bug_2799.py new file mode 100644 index 000000000..eb86c7d4b --- /dev/null +++ b/sources/pyside6/tests/QtAsyncio/bug_2799.py @@ -0,0 +1,30 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +from __future__ import annotations + +"""Test cases for QtAsyncio""" + +import unittest +import asyncio +import sys + +import PySide6.QtAsyncio as QtAsyncio + + +@unittest.skipIf(sys.version_info < (3, 11), "Requires ExceptionGroup") +class QAsyncioTestCaseBug2799(unittest.TestCase): + async def job(self): + await asyncio.sleep(1) + + async def main(self): + async with asyncio.TaskGroup() as tg: + tg.create_task(self.job()) + raise RuntimeError() + + def test_exception_group(self): + with self.assertRaises(ExceptionGroup): + QtAsyncio.run(self.main(), keep_running=False) + + +if __name__ == "__main__": + unittest.main() |
