Skip to content

[asyncio] cancelling task cancels awaited task instead #138717

@Tinche

Description

@Tinche

The issue boils down to this line:

if self._fut_waiter.cancel(msg=msg):

First off the bat, I realize this may be impossible to change due to backwards comp. Still, let's discuss.

Task A awaits task B. Someone cancels task A. Task B gets cancelled instead.

This probably makes sense in some contexts, for example if task A is the logical owner/parent of task B.
But in my case, task B was created in a long-lived taskgroup. Its lifecycle is independent of task A. They are now coupled by this invisible link created by the await.

I wonder if we could make this cancellation forwarding be skipped in some cases, like if the awaitee was created through a task group (since that mitigates the danger of leaking tasks).

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions