-
Notifications
You must be signed in to change notification settings - Fork 244
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
task cancellation communication #211
Comments
Note that in your example, There's some very relevant discussion happening at python-trio/trio#147 though I'm afraid it doesn't come to any useful conclusions yet. Except that reliable graceful shutdown in modular programs is not trivial. (Note that "shielding" is trio's version of |
It's true that this won't quite work right since cancellation requests can only be delivered at await statements. However, you could probably make it work by adding an explicit
There would need to be some additional work to make I agree with Nathaniel that graceful shutdown is not easy. Curio doesn't really do anything beyond the delivery of the appropriate cancellation exceptions. Your code can take action on those as it sees fit, but it will require some amount of care to make sure everything cancels gracefully. |
my understanding of passing exceptions to coroutines is hazy. what i thought may happen is that kernel/scheduler 'pins' the GracefulError exception to the kid task instead of |
@goldcode: that would make sense – in fact, I'm pretty sure that's how I did it when I first implemented (Minor editorial comment: this ongoing difficulty in figuring out where cancellation points are in curio was the straw that made me switch to writing trio.) There's another challenge to handling multiple "cancellation types", which is how to adjudicate between them if several are used at the same time. Like, if you do |
For various reasons, cancellation exceptions are not raised in the Regarding cancellation in Curio generally, it can theoretically happen on any operation involving an As for a task being cancelled from two places--don't do that. |
@njsmith w.r.t cancelling a task multiple times before the task can even respond. interesting. i don't know what curio currently would do, but the behavior should be deterministic, (e.g. like warn or throw an exception on a second cancel attempt to avoid any subtle bugs.) This scenario is a statistical eventuality (bug waiting to happen) even if it's not explicitly wished by the programmer to cancel twice. |
I've pushed a partial change that at least allows a custom exception to be raised via Regarding second cancellation--the current behavior of cancellation is that whatever cancellation request was received first is what gets processed and delivered. If, for whatever reason, multiple tasks were to attempt cancellation on the same task, the second request would basically be ignored. Both cancellation requests, however, would block waiting for the task to terminate. I suppose an exception or warning could be issued if an attempt was made to cancel a task with a different kind of exception than one that was already in progress. |
Just had a thought about how tasks can communicate via exceptions with one another (using cancel and disable_cancellation) i have a use case where a task may need to be cancelled gracefully or mercilessly. here is how the future code could look like. don't know if it's even possible, just a thought...
The text was updated successfully, but these errors were encountered: