-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
Add an asyncio.TaskGroup.cancel method #108951
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancementA feature request or enhancement
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
Done
Feature or enhancement
Proposal:
Trio/anyio have a way to cancel all tasks within a taskgroup, via
taskgroup.cancel_scope.cancel().Asyncio doesn't have cancel scopes. The way to currently do this is to cancel the task which the taskgroup is a child of, but there are problems with this approach:
To fix this, I propose to add a
taskgroup.cancelmethod which behaves liketask.cancelif the taskgroup is still active (i.e. not aborting).If this change is likely to be accepted I'm OK with writing a PR.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/how-to-cancel-all-tasks-created-within-same-taskgroup/30215
Linked PRs
asyncio.TaskGroup#123837