-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
Can we talk about "cancelled" instead of "cancelled_caught" and "raised Cancelled" and similar circumlocutions? #885
Comments
FWIW, I strongly support this. The result of cancelling something is either (a) the called code didn't do anything, raising a It's probably out of Trio's scope to signal that state to the caller; there should be an attribute "is this object still usable", and/or the object should raise an |
Unfortunately I don't think the cancel scope machinery has any realistic way to tell the difference between these two cases. I guess we could try doing something wacky like counting how many checkpoints there were (cancelled on first checkpoint = didn't do anything?), but I think that'd be super fragile in practice. Anyway, the whole partial cancellation topic has been coming up a lot, so I opened #889 to consolidate the threads... Back on the topic of this issue: I should also link to #886, which contains an idea that involves getting rid of |
I don't want it to. Deciding whether a cancelled
If the stream in question can send an Yes, this scheme needs to be supported by everything that has a |
I definitely support a rename here! I'd suggest |
comment today by a colleague:
If the cancel scope happens to be within a loop, it ends up being more readable to avoid the attribute altogether with something like: while True:
with trio.move_on_after(10):
await foo()
continue
# do something here relevant to cancel-caught case only |
In this comment, @mehaase wrote:
I'm actually not sure what he's quoting, but it sure sounds like something I'd write in the docs, especially back when I was still struggling to come to grips with fine distinctions like
cancel_scope.cancel_called
versuscancel_scope.cancelled_caught
. And I'm pretty sure the reason I didn't say "if a call tosend_all()
is cancelled" is because technically you could call.cancel()
on a scope surrounding a call tosend_all
but the call didn't raiseCancelled
because it had already passed the point of no return. Which... is technically accurate, but as Mark points out, super confusing to ordinary humans. And probably saying "if a call tosend_all()
is cancelled" would be totally clear to actual readers; if the tiny edge case was pointed out they'd just shrug and think "well, I guess it wasn't cancelled then".And btw the distinction between
.cancel_called
and.cancelled_caught
is also super confusing to regular humans.Maybe we should change the official way of talking about this to more like:
cancel_scope.cancel()
requests a cancellation, but code might or might not actually be cancelled (= raiseCancelled
).That would suggest renaming the
CancelScope
attributes to something like.cancel_requested
and.cancel_succeeded
, and also probably updating the docs to use this language more uniformly (though I haven't read through the docs to check).The text was updated successfully, but these errors were encountered: