-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Open
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-asynciotype-featureA feature request or enhancementA feature request or enhancement
Description
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:
- the task is a private member of the taskgroup, so the task is inaccessible through it
- what about nested taskgroups?
- also passing the task around is additional overhead and risks cancelling it when the taskgroup is no longer active
To fix this, I propose to add a taskgroup.cancel
method which behaves like task.cancel
if 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
heckad, mslynch, arthur-tacca and TheJJ
Metadata
Metadata
Assignees
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-asynciotype-featureA feature request or enhancementA feature request or enhancement
Projects
Status
Todo