summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/base_tasks.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2022-02-15 23:42:04 (GMT)
committerGitHub <noreply@github.com>2022-02-15 23:42:04 (GMT)
commit602630ac1855e38ef06361c68f6e216375a06180 (patch)
tree58a3f509fd92945d2676b0030c251713461460b6 /Lib/asyncio/base_tasks.py
parent08ec80113b3b7f7a9eaa3d217494536b63305181 (diff)
downloadcpython-602630ac1855e38ef06361c68f6e216375a06180.zip
cpython-602630ac1855e38ef06361c68f6e216375a06180.tar.gz
cpython-602630ac1855e38ef06361c68f6e216375a06180.tar.bz2
bpo-46752: Add TaskGroup; add Task..cancelled(),.uncancel() (GH-31270)
asyncio/taskgroups.py is an adaptation of taskgroup.py from EdgeDb, with the following key changes: - Allow creating new tasks as long as the last task hasn't finished - Raise [Base]ExceptionGroup (directly) rather than TaskGroupError deriving from MultiError - Instead of monkey-patching the parent task's cancel() method, add a new public API to Task The Task class has a new internal flag, `_cancel_requested`, which is set when `.cancel()` is called successfully. The `.cancelling()` method returns the value of this flag. Further `.cancel()` calls while this flag is set return False. To reset this flag, call `.uncancel()`. Thus, a Task that catches and ignores `CancelledError` should call `.uncancel()` if it wants to be cancellable again; until it does so, it is deemed to be busy with uninterruptible cleanup. This new Task API helps solve the problem where TaskGroup needs to distinguish between whether the parent task being cancelled "from the outside" vs. "from inside". Co-authored-by: Yury Selivanov <yury@edgedb.com> Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Diffstat (limited to 'Lib/asyncio/base_tasks.py')
-rw-r--r--Lib/asyncio/base_tasks.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/asyncio/base_tasks.py b/Lib/asyncio/base_tasks.py
index 09bb171..1d62389 100644
--- a/Lib/asyncio/base_tasks.py
+++ b/Lib/asyncio/base_tasks.py
@@ -8,7 +8,7 @@ from . import coroutines
def _task_repr_info(task):
info = base_futures._future_repr_info(task)
- if task._must_cancel:
+ if task.cancelling() and not task.done():
# replace status
info[0] = 'cancelling'