Skip to content

Commit

Permalink
Do not wait for code completions in live kernels (#13233)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Mar 30, 2023
1 parent f7e0403 commit b31f7e1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/kernels/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,14 @@ export async function executeSilently(
.join()
.substring(0, 100)}}`
);
if (errorOptions?.traceErrors) {
const errorMessage = `${
errorOptions.traceErrorsMessage || 'Failed to execute (silent) code against the kernel'
}, \nCode = ${code}\nError details: `;
traceError(
`${errorMessage} ${msg.content.ename},${msg.content.evalue}, ${msg.content.traceback.join()}`
);
}
const output: nbformat.IError = {
ename: msg.content.ename,
evalue: msg.content.evalue,
Expand Down
41 changes: 29 additions & 12 deletions src/kernels/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,18 +685,35 @@ abstract class BaseKernel implements IBaseKernel {
// Restart sessions and retries might make this hard to do correctly otherwise.
session.registerCommTarget(Identifiers.DefaultCommTarget, noop);

// As users can have IPyWidgets at any point in time, we need to determine the version of ipywidgets
// This must happen early on as the state of the kernel needs to be synced with the Kernel in the webview (renderer)
// And the longer we wait, the more data we need to hold onto in memory that later needs to be sent to the kernel in renderer.
await this.determineVersionOfIPyWidgets(session);

// Gather all of the startup code at one time and execute as one cell
const startupCode = await this.gatherInternalStartupCode();
await this.executeSilently(session, startupCode, {
traceErrors: true,
traceErrorsMessage: 'Error executing jupyter extension internal startup code'
});
if (this.kernelConnectionMetadata.kind !== 'connectToLiveRemoteKernel') {
if (this.kernelConnectionMetadata.kind === 'connectToLiveRemoteKernel') {
// As users can have IPyWidgets at any point in time, we need to determine the version of ipywidgets
// This must happen early on as the state of the kernel needs to be synced with the Kernel in the webview (renderer)
// And the longer we wait, the more data we need to hold onto in memory that later needs to be sent to the kernel in renderer.
this.determineVersionOfIPyWidgets(session).catch((ex) =>
traceError(`Failed to determine IPyWidget version`, ex)
);

// Gather all of the startup code at one time and execute as one cell
this.gatherInternalStartupCode()
.then((startupCode) =>
this.executeSilently(session, startupCode, {
traceErrors: true,
traceErrorsMessage: 'Error executing jupyter extension internal startup code'
})
)
.catch((ex) => traceError(`Failed to execute internal startup code`, ex));
} else {
// As users can have IPyWidgets at any point in time, we need to determine the version of ipywidgets
// This must happen early on as the state of the kernel needs to be synced with the Kernel in the webview (renderer)
// And the longer we wait, the more data we need to hold onto in memory that later needs to be sent to the kernel in renderer.
await this.determineVersionOfIPyWidgets(session);

// Gather all of the startup code at one time and execute as one cell
const startupCode = await this.gatherInternalStartupCode();
await this.executeSilently(session, startupCode, {
traceErrors: true,
traceErrorsMessage: 'Error executing jupyter extension internal startup code'
});
// Run user specified startup commands
await this.executeSilently(session, this.getUserStartupCommands(), { traceErrors: false });
}
Expand Down

0 comments on commit b31f7e1

Please sign in to comment.