Skip to content

Delay deciding which cancel scope a Cancelled exception belongs to #860

@njsmith

Description

@njsmith

Right now, whenever we create a Cancelled exception, we immediately tag it with the cancel scope that's going to catch it.

There's another option that's briefly mentioned in #606: we could wait until CancelScope.__exit__ to decide whether a given Cancelled exception "belongs" to this scope. The check would be "on the current task's stack, am I the outermost unshielded scope that's in the cancelled state?"

This can behave differently from what we have now in cases where there are multiple cancelled CancelScopes on the stack.

I'm not entirely sure if this would actually help with #606, because of complications noted there (hello KeyboardInterrupt). But it would probably simplify the cancel scope code in general, in particular _cancel_no_notify, and the issues described in this comment: #835 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions