aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/PySide6/QtAsyncio/tasks.py
diff options
context:
space:
mode:
authorAdrian Herrmann <adrian.herrmann@qt.io>2024-07-16 22:20:21 +0200
committerAdrian Herrmann <adrian.herrmann@qt.io>2024-07-19 17:20:13 +0200
commitd1e400c62d7e5453007c0434e82301385e983d20 (patch)
treeb7c8144b1b77dcec5d9f4e5b94c87146ae0d9d66 /sources/pyside6/PySide6/QtAsyncio/tasks.py
parent2953affcf7d737bc942d2ecb6953167ef02b22ff (diff)
QtAsyncio: Add clarifying comments
Add a few more clarifying comments regarding to previous bug fixes or non-obvious variable usages. Pick-to: 6.7 Task-number: PYSIDE-2644 Task-number: PYSIDE-769 Change-Id: Ic4db10510e1adf8141efa83d727f519547d67b24 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/pyside6/PySide6/QtAsyncio/tasks.py')
-rw-r--r--sources/pyside6/PySide6/QtAsyncio/tasks.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/sources/pyside6/PySide6/QtAsyncio/tasks.py b/sources/pyside6/PySide6/QtAsyncio/tasks.py
index 34daa3b2b..be1809d5c 100644
--- a/sources/pyside6/PySide6/QtAsyncio/tasks.py
+++ b/sources/pyside6/PySide6/QtAsyncio/tasks.py
@@ -30,10 +30,12 @@ class QAsyncioTask(futures.QAsyncioFuture):
# The task step function executes the coroutine until it finishes,
# raises an exception or returns a future. If a future was returned,
- # the task will await its completion (or exception).
+ # the task will await its completion (or exception). If the task is
+ # cancelled while it awaits a future, this future must also be
+ # cancelled in order for the cancellation to be successful.
self._future_to_await: asyncio.Future | None = None
- self._cancelled = False
+ self._cancelled = False # PYSIDE-2644; see _step
self._cancel_count = 0
self._cancel_message: str | None = None
@@ -118,11 +120,17 @@ class QAsyncioTask(futures.QAsyncioFuture):
# called again.
result.add_done_callback(
self._step, context=self._context) # type: ignore[arg-type]
+
+ # The task will await the completion (or exception) of this
+ # future. If the task is cancelled while it awaits a future,
+ # this future must also be cancelled.
self._future_to_await = result
+
if self._cancelled:
- # If the task was cancelled, then a new future should be
- # cancelled as well. Otherwise, in some scenarios like
- # a loop inside the task and with bad timing, if the new
+ # PYSIDE-2644: If the task was cancelled at this step and a
+ # new future was created to be awaited, then it should be
+ # cancelled as well. Otherwise, in some scenarios like a
+ # loop inside the task and with bad timing, if the new
# future is not cancelled, the task would continue running
# in this loop despite having been cancelled. This bad
# timing can occur especially if the first future finishes
@@ -186,7 +194,7 @@ class QAsyncioTask(futures.QAsyncioFuture):
# A task that is awaiting a future must also cancel this future in
# order for the cancellation to be successful.
self._future_to_await.cancel(msg)
- self._cancelled = True
+ self._cancelled = True # PYSIDE-2644; see _step
return True
def uncancel(self) -> int: