GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-108951: document addition of TaskGroup.cancel() by belm0 · Pull Request #149031 · python/cpython

Conversation

@belm0

@belm0 belm0 commented Apr 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Follow up to gh-127214.

  • Issue: Add an asyncio.TaskGroup.cancel method #108951

📚 Documentation preview 📚: https://cpython-previews--149031.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@belm0
pythongh-108951: Whatsnew and doc tweaks for TaskGroup.cancel()
2bf9185
@belm0
belm0 requested review from 1st1, AA-Turner, asvetlov, kumaraditya303 and willingc as code owners April 26, 2026 22:59
@bedevere-app bedevere-app Bot added awaiting review docs Documentation in the Doc dir labels Apr 26, 2026
@github-project-automation github-project-automation Bot added this to Docs PRs Apr 26, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Apr 26, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Apr 26, 2026
Add an asyncio.TaskGroup.cancel method #108951
Closed
@belm0 belm0 mentioned this pull request Apr 26, 2026
gh-108951: add TaskGroup.cancel() #127214
Merged
agronholm
agronholm reviewed Apr 26, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2024-11-24-07-18-40.gh-issue-108951.jyKygP.rst Outdated
@@ -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`.

@agronholm agronholm Apr 26, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@agronholm agronholm Apr 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further, this still begs to question why you said "without raising :exc:asyncio.CancelledError". This implies that otherwise it would raise a CancelledError, yes?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@belm0 belm0 Apr 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@agronholm agronholm Apr 27, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be reworded:

Add :meth:~asyncio.TaskGroup.cancel which cancels unfinished tasks in the group and prevents new ones from being created. If this requires cancellation of the host task, the task group will swallow the :exc:asyncio.CancelledError, unless the task was also cancelled from elsewhere.

Thoughts?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
agronholm
agronholm reviewed Apr 26, 2026
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@belm0 @agronholm
formatting
e6a42b9
Co-authored-by: Alex Grönholm <[email protected]>
picnixz
picnixz reviewed Apr 27, 2026
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@picnixz picnixz changed the title gh-108951: Whatsnew and doc tweaks for TaskGroup.cancel() gh-108951: document addition of TaskGroup.cancel() Apr 27, 2026
gvanrossum
gvanrossum approved these changes Apr 27, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Apr 27, 2026
gvanrossum
gvanrossum reviewed Apr 28, 2026
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, just one suggestion.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@picnixz
Update Doc/whatsnew/3.15.rst
ccdc58e
picnixz
picnixz approved these changes Apr 28, 2026
View reviewed changes
picnixz
picnixz reviewed Apr 28, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2024-11-24-07-18-40.gh-issue-108951.jyKygP.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Apr 28, 2026
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz added 2 commits April 28, 2026 09:48
@picnixz
Wrap lines under 80 characters.
c67dbab
@picnixz
Use TaskGroup.cancel in NEWS entry for the link
305ad78
@picnixz

picnixz commented Apr 28, 2026

Copy link
Copy Markdown
Member

I've updated the rST markup because otherwise it will only show "cancel()" as a link and the user won't know whether it's asyncio.cancel or asyncio.something.cancel(). Apart from the rewording of the NEWS entry that I have no strong opinion about, I think we can merge this.

gvanrossum reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gvanrossum
gvanrossum approved these changes Apr 28, 2026
View reviewed changes
@gvanrossum
gvanrossum merged commit 8a8d737 into python:main Apr 28, 2026
30 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Apr 28, 2026
@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 28, 2026
@belm0
belm0 deleted the taskgroup_cancel_docs branch April 29, 2026 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@picnixz picnixz picnixz approved these changes
@gvanrossum gvanrossum gvanrossum approved these changes
@1st1 1st1 Awaiting requested review from 1st1 1st1 is a code owner
@asvetlov asvetlov Awaiting requested review from asvetlov asvetlov is a code owner
@kumaraditya303 kumaraditya303 Awaiting requested review from kumaraditya303 kumaraditya303 is a code owner
@willingc willingc Awaiting requested review from willingc willingc is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
+1 more reviewer
@agronholm agronholm agronholm left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

docs Documentation in the Doc dir

Projects

Docs PRs
Status: Done

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@belm0 @picnixz @agronholm @gvanrossum
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.