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
#11817 Add twisted.internet.defer.race #11818
Conversation
please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started reviewing this, and while I was picking my way through the very extensive comments in race
, it struck me that this was a partial reimplementation of most of the logic in DeferredList
. I don't particularly love DeferredList
's implementation, but as the story goes, "one big pile is better than two little piles, and rather than bring that one up we decided to throw ours down".
I put a draft PR up here to see how you feel about that approach: #11819
I seem to have become mildly obsessed with golfing this problem. The other thing that occurred to me was that this generalizes quite neatly into something I find myself wanting a lot; specifically, the word "race" makes me think that you're getting 1st through Nth place rather than a single winner. So here's the version expressed in terms of that abstraction: https://github.com/twisted/twisted/pull/11820/files#diff-8d95429e1233c1c5f25e6f0acd93c6819745e8b6a6041b11b621c393cbaeac69R1514-R1538 |
Can I convince you that instead of making the DeferredList pile bigger, we can chip away at it until it disappears? Nobody likes DeferredList. Nobody can remember how all of its corners work. Any change to any part of it involves understanding and preserving all of the other parts. Replacing it with 4 or 5 narrowly focused APIs (maybe with their own implementation, maybe with some shared implementation, if there's a way to do it that's simple enough) seems like a good idea to me. |
To second Jean-Paul: I used |
What a coincidence! In my attempted fix I updated the type annotation to correctly express this unfortunate brokenness :-\ so perhaps we should adopt that modification from that branch, if nothing else. |
I could get on board with this as a plan, but the implementation for I like where I ended up with So, let's forget about the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I should not be holding this up because I think there's a better underlying implementation. The interface is fine; I can land a refactoring later.
I would consider renaming MultiFailure
to FailureGroup
, to parallel the stdlib's ExceptionGroup
. I think we may want to support PEP 654 here at some point.
Thanks. And I have no problem with future factoring improvements to the implementation of this, I just don't have time to pursue them at the moment.
👍 |
Scope and purpose
Fixes #11817
One thing I'm not sure about is whether
race
should accept and returnDeferred
orAwaitable
(or something more esoteric ..Coroutine[Deferred[T], Any, T]
?). The gymnastics to make cancellation work if it operates onAwaitable
are not clear to me, though (and might just amount to "this works for any Awaitable as long as it is Deferred").Contributor Checklist:
This process applies to all pull requests - no matter how small.
Have a look at our developer documentation before submitting your Pull Request.
Below is a non-exhaustive list (as a reminder):
please review
.Our bot will trigger the review process, by applying the pending review label
and requesting a review from the Twisted dev team.