Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
njsmith opened this issue Jan 27, 2018 · 2 comments
Labels

Comments

@njsmith
Copy link
Member

njsmith commented Jan 27, 2018

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).

@njsmith njsmith added the docs label Jan 27, 2018
@njsmith
Copy link
Member Author

njsmith commented Jan 27, 2018

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

@njsmith
Copy link
Member Author

njsmith commented Jan 27, 2018

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
Labels
Projects
None yet
Development

No branches or pull requests

1 participant