Skip to content

Add an example to the tutorial that demonstrates collecting results from tasks #421

Open

Description

@njsmith

For example, maybe something like:

https://gist.github.com/njsmith/986b0d0e04c3b2bb45de5d662ae873d5

Or the same but with results[i] = await trio.hazmat.Result.acapture(async_fn).

Activity

  1. njsmith commented on Jan 27, 2018

    @njsmith
    MemberAuthor

    "How do I make a nursery that ignores child failures" might be a similar good example to have (also good example of MultiError.catch).

  2. njsmith commented on Jan 27, 2018

    @njsmith
    MemberAuthor

    Actually, using Result.acapture in that example is wrong, because it'll swallow KeyboardInterrupt and Cancelled exceptions. We want something more like a conventional catch-all handler, like except Exception. And conventionally that would mean it needs to be replaced by MultiError.catch. Here we only really want to catch the Exception part of the MultiError, but in the common case where that's the whole MultiError, we want to preserve it as a single MultiError that we can pack into an Error object and add to the results list. Hmm.

    I wonder if we should add something like a MultiError.split primitive that divides a MultiError into two pieces, those that match the predicate and those that don't... And maybe a catch_split built on it that catches all exceptions of a given class and hands them all at once to a handler? These might actually be the primitives we want for both cancel scopes and the log-and-discard-errors cases.

    See also #285, #59, #408, ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions