Skip to content
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

log errors that occur in bg threads #15491

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/standalone/api/kernels/backgroundExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export async function execCodeInBackgroundThread<T>(
const api = createKernelApiForExtension(JVSC_EXTENSION_ID, kernel, { accessAllowed: true });
const mime = `application/vnd.vscode.bg.execution.${counter}`;
const mimeFinalResult = `application/vnd.vscode.bg.execution.${counter}.result`;
const mimeErrorResult = `application/vnd.vscode.bg.execution.${counter}.error`;
let displayId = '';

const codeToSend = `
def __jupyter_exec_background__():
from IPython.display import display
from threading import Thread
from traceback import format_exc

# First send a dummy response to get the display id.
# Later we'll send the real response with the actual data.
Expand All @@ -41,8 +43,8 @@ def __jupyter_exec_background__():
def bg_main():
try:
output.update({"${mimeFinalResult}": do_implementation()}, raw=True)
except:
pass
except Exception as e:
output.update({"${mimeErrorResult}": format_exc()}, raw=True)


Thread(target=bg_main, daemon=True).start()
Expand Down Expand Up @@ -85,6 +87,11 @@ del __jupyter_exec_background__
if (token.isCancellationRequested) {
return;
}
const error = output.items.find((item) => item.mime === mimeErrorResult);
if (error) {
traceWarning('Error in background execution:\n', new TextDecoder().decode(error.data));
return;
}
const metadata = getNotebookCellOutputMetadata(output);
if (!metadata?.transient?.display_id) {
continue;
Expand Down
Loading