-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
Some way to take a cancellation in one call to wait_task_rescheduled and forward it to another task #642
Comments
See also: #961 (comment) |
I started working on an implementation of this where each task has a "cancellation parent" which is a nursery or other task that determines where in the CancelStatus tree this task is attached. Normally the cancellation parent is the task's parent nursery, which gives the usual Trio semantics, but you can also set it to another task, and then you get the semantics discussed here. For example, the system task created by To support most of the interesting use cases, the cancellation parent has to be modifiable during the task's lifetime:
But having the cancellation parent be modifiable turns out to create a number of challenges:
All of these are resolvable, but the solutions add complexity, so I figured it was worth checking back to see whether this is something we care about at all? #606 can be resolved by running reentrant child tasks in the original parent task rather than as system tasks, #266 can be done without core cooperation, and nursery.start() is fine as-is. If we think it's worth it, I can complete the cancellation_parent work and upload a PR; if not, probably best to just close this issue. |
Typing that all out made me think of a better abstraction, though!
I think the main argument for this, rather than the alternative of manual propagation of cancellations, is that we can make it not break if/when we add more cancellation features (graceful, etc). |
I've come around to thinking that maybe this is the wrong problem to try to solve, and we should handle (I know there's an issue somewhere that talks about making |
Oh and for |
In both #266 (shared tasks) and #606 (propagating cancellation across thread re-entry), we have a situation where we're pushing work from one place to another, so to Python (and the Trio core) it looks like two independent tasks, but logically it's one stack split over multiple tasks. Specifically:
wait_task_rescheduled
to wait for it to finishwait_task_rescheduled
gets aborted, we want to propagate the cancellation to the system task, so that the cancellation actually works, and so that it gets raised at the appropriate place (the actual bottom of our stack), and ends up with a proper tracebackThis is quite difficult currently.
What we want conceptually is like... to be able to open a cancel-scope-or-something-like-it in the system task, and then somehow "forward" cancellations from the original context to it. It's not immediately obvious to me how to do this with the current cancellation code – in particular there are subtleties like, if the parent context is cancelled normally, then we should put the child into a persistent cancelled state, and keep attempting to redeliver
Cancelled
with the parent's scope. If the parent has aKeyboardInterrupt
delivered, we should try to forward on theraise_cancel
logic to the child, so that if-and-only-if it accepts the exception, thepending_ki
flag gets cleared.The text was updated successfully, but these errors were encountered: