Skip to content

Proposal: make checkpoint_if_cancelled() sync-colored and rename it accordingly #961

Open
@oremanj

Description

@oremanj

I'd like to propose that we deprecate checkpoint_if_cancelled() in favor of a synchronous function that I'm thinking of as trio.check_cancelled() (happy to take suggestions on the name, or move into hazmat). This would raise Cancelled if the current scope is cancelled, and do nothing otherwise. i.e., it is a pure cancel point, not a schedule point, not even a schedule point if we're cancelled.

This becomes possible due to some recent or pending changes:

And I think would have benefits for:

Possible downside: a sync-colored function called from an async function can now call check_cancelled() and wind up raising Cancelled. Previously that couldn't happen. My feeling is that "functions that do something off-the-wall might raise an exception their caller wasn't expecting" is hardly a new problem, but maybe there's some aspect of what we'd be giving up here that I'm missing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions