-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Execution API #116416
Execution API #116416
Conversation
39d32bd
to
b06acb0
Compare
Noticed one issue, if extensions can initiate an execution with This also loses the relationship between a "job" of multiple cells executing and one cancellation token for the job. But I'm not sure we want that anyway. VS Code can't have any concept of multiple cells executing together unless the execution object can be created for multiple cells together. |
src/vs/vscode.proposed.d.ts
Outdated
export function createNotebookCellExecution(cell: NotebookCell, startTime?: number): NotebookCellPending; | ||
|
||
// todo@API who needs this event? | ||
export const onDidChangeNotebookCellExecutionState: Event<{ cell: NotebookCell, state: any }>; // idle -> pending -> executing -> idle |
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 believe it would be for LiveShare but for now we can pretend that we don't know that and not have this
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 was thinking that liveshare takes over the kernel or something but I guess I don't know exactly how it works
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 guess it probably doesn't do that on the host and it just has to observe
Wouldn't |
Yes, just the cancellation token case where you care which cell I clicked stop on would not work |
3938228
to
772c34a
Compare
Tried to implement some working form of the I think some things will be clear with more implementation. One thing I've decided is that executeCells can't pass a cancellation token or execution object to the kernel, partly because executeCells is a call for multiple cells, partly because a token doesn't make sense in a void method - what is the lifetime? We can't create a cancel token until the kernel puts the cell in the pending state by calling the create method. Ideally we would be able to say that a cell is pending the instant the run button is clicked without a roundtrip to the kernel. This is probably still possible but it's much simpler to ignore it for now. Since the kernel is the real source of truth about whether a cell is executing, it's better to say that it's not pending until the kernel says it is, and then vscode probably does not do any validation on whether it's ok to call create. Avoids issues about what happens if the user clicks the run button at the exact same time as the kernel independently says that a cell has started executing. We could also make I think the info about the run state will be internally moved out of metadata to some other object that is edited in the same way with workspace edits and cell edits. |
I've had an idea for a different shape for this API which would make some things simpler, which would look something like this: interface NotebookKernel {
executeCells(document: NotebookDocument, cells: NotebookCellRange[], executionObject: NotebookCellExecution): Promise<SomeResult>;
}
// Kernel can call executeCommand('executeCell', { cell }); to trigger an execution Peng and I discussed this. It's more in a direction similar to what we have today but keeps the execution object concept. Essentially the execution object would only be created by vscode and passed via the executeCells API, and if a kernel needs to trigger an execution, it would call some API or use executeCommand to do that, and vscode would call Pros are that it would give more of a "single direction" of data flow between vscode and the kernel. The run button clicking case and the kernel-initiated execution case would work exactly the same way. The executeCells API really feels like it should return a promise that actually follows the lifetime of the execution process, and this enables that. Cons are that this inverses the relationship between vscode and the kernel. If the kernel really is the source of truth about whether a cell is executing, then it's wrong to have an API model where the kernel has to request that vscode start executing a cell. Really it has to be vscode that requests that the kernel start an execution, and the kernel telling vscode that it is executing. Tbh I'm having trouble telling whether this is just a philosophical problem or a real one. But I think that this solution has to lead to vscode being the one to maintain the execution state of a cell, rather than the kernel. Also the shape above is not correct, we would need to figure out how to pass N execution objects for cells in the range, which is weird, or change the API to execute a single cell, which is also weird. |
After exploring different options, I do prefer the execution object concept as it's a good abstraction of the challenge kernels are dealing handling. As long as we support multiple cell selection in the UI, the first thing extension authors need to think about is how to handle execution when more than one cell is selected. We as extension authors would need to answer a couple of questions
The execution object concept is a proper way to do cell level execution state manipulation. Relying to_be_continued |
When a kernel is becoming the selected/active kernel, e.g when calling |
Notes to myself since I'm going in circles during discussion, there are a couple of scenarios we want to support and also a few No-gos
|
This is more along the lines of the original suggestion (that is currently implemented in this PR) where the kernel creates execution objects. I like being able to restrict the execution object creation to the active kernel though. There should be no race or other but when switching kernels where a kernel might be confused about whether it is active, vscode has to be able to enforce this. |
05579e1
to
27b9f64
Compare
extensions/vscode-api-tests/src/singlefolder-tests/notebook.test.ts
Outdated
Show resolved
Hide resolved
// TODO@roblou more to do here? | ||
// TODO@roblou also validate kernelId, once kernel has moved from editor to document | ||
if (this._activeExecutions.has(cell.uri)) { | ||
return; |
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.
Unsure if this should be prohibited and iff so you must also check on the renderer because there are N extension hosts
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.
If only the active kernel is allowed to have executions, then I think this is sufficient. That isn't implemented but I think we want that.
0b8fdb5
to
c5a766e
Compare
Remaining TODOs
|
c5a766e
to
0e37ad2
Compare
This reverts commit 1251a3b.
f1396e7
to
2cb1ba8
Compare
#106744
#106741
#105847
cc @rebornix @jrieken