-
Notifications
You must be signed in to change notification settings - Fork 389
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
KernelInvocationContext.Current.CancellationToken
is unreliable in VS Code
#2987
Comments
Recent improvements in #2982 might have improved this. |
This seems to have been fixed (kind of). My code still doesn't get notified of the cancellation through the token, but the program is actually terminated now. Is the expectation that canceling is effectively the same as "force stop" where there is no opportunity for cleanup? |
Cancellation is best effort. Any code path that's not checking the An API to actually force a stop (a kind of replacement for the .NET Framework-only |
Still have the same issue not being able to dispose of resources |
Looking at this again, I realized that I misunderstood what's happening here. This is subtle and deserves a detailed explanation. TL;DR: It works as intended. 😮 Every line of the code above should run because the Ok, so I realized that the code in the example here is not doing what folks probably think it's doing. I added a simple variable assignment ( Note the value for So what's going on? What happened to Console output is only intercepted and written to the output cell during the lifetime of the This behavior is unintuitive enough that it could be considered a bug, and I'm going to take a look at whether it's possible to stop listening to those events just a little bit later so that console output isn't lost this way. (#3772) |
If you need to dispose of resources at the end of the current cell execution, and you're doing something like |
Describe the bug
I've tried using
KernelInvocationContext.Current.CancellationToken
to cancel long-running tasks as described here but it rarely ever works.Please complete the following:
Which version of .NET Interactive are you using? (In a notebook, run the
#!about
magic command. ):Reproduction
Just keep running the above reproduction, clicking the "Cancel" button before 15s, and you're bound to run into the problem.
The text was updated successfully, but these errors were encountered: