gh-108951: Whatsnew and doc tweaks for TaskGroup.cancel()#149031
gh-108951: Whatsnew and doc tweaks for TaskGroup.cancel()#149031belm0 wants to merge 2 commits intopython:mainfrom
Conversation
| @@ -1 +1 @@ | |||
| Add :meth:`~asyncio.TaskGroup.cancel` which cancels unfinished tasks and exits the group without error. | |||
| Add :meth:`~asyncio.TaskGroup.cancel` which cancels unfinished tasks and exits the group without raising :exc:`asyncio.CancelledError`. | |||
There was a problem hiding this comment.
I'm still not sure if the explicit "and exits the group without raising :exc:asyncio.CancelledError" makes sense. All this does is 1) cancel all current tasks in the group and 2) set the task group into aborted mode which causes creation of further tasks to fail. With that in mind, I'm not sure why you chose to explicitly mention exiting the task group.
There was a problem hiding this comment.
Further, this still begs to question why you said "without raising :exc:asyncio.CancelledError". This implies that otherwise it would raise a CancelledError, yes?
There was a problem hiding this comment.
well, if you check the long discussions in the impl PR, there was quite a bit made about possible confusion from expecting TaskGroup.cancel() to behave like Task.cancel(). So this is being explicit that unlike the latter, TaskGroup.cancel() does not cause anything to raise CancelledError.
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
Follow up to gh-127214.
asyncio.TaskGroup.cancelmethod #108951📚 Documentation preview 📚: https://cpython-previews--149031.org.readthedocs.build/