Skip to content

Commit 90b6ddc

Browse files
sok82Sergey Kadnikov
andauthored
Rework of monitoring output execution together with execution phase (#312)
* Added Output with monitoring sampe * 290 - rework of output monitoring getting execution phase and output model together * 290 - Rework of output monitoring getting execution phase and output model together --------- Co-authored-by: Sergey Kadnikov <skadnikov@seeneco.ru>
1 parent 7ca1011 commit 90b6ddc

File tree

9 files changed

+346
-156
lines changed

9 files changed

+346
-156
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ packages/*/content
155155
# Static
156156
**/static/*
157157

158+
# VS Code settings
159+
packages/react/.vscode/launch.json
160+
158161
# Include
159162
!**/.*ignore
160163
!**/.*rc

packages/react/src/components/output/Output.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@
55
* MIT License
66
*/
77

8-
import { useState, useEffect } from 'react';
9-
import { Box } from '@primer/react';
108
import { IOutput } from '@jupyterlab/nbformat';
119
import { IOutputAreaModel } from '@jupyterlab/outputarea';
1210
import { KernelMessage } from '@jupyterlab/services';
13-
import { newUuid } from '../../utils';
11+
import { Box } from '@primer/react';
12+
import { useEffect, useState } from 'react';
1413
import { useJupyter } from '../../jupyter/JupyterContext';
1514
import { Kernel } from '../../jupyter/kernel/Kernel';
16-
import { KernelActionMenu, KernelProgressBar } from './../kernel';
17-
import { Lumino } from '../lumino/Lumino';
15+
import { newUuid } from '../../utils';
1816
import { CodeMirrorEditor } from '../codemirror/CodeMirrorEditor';
17+
import { Lumino } from '../lumino/Lumino';
18+
import { KernelActionMenu, KernelProgressBar } from './../kernel';
1919
import { OutputAdapter } from './OutputAdapter';
2020
import { OutputRenderer } from './OutputRenderer';
2121
import { useOutputsStore } from './OutputState';
2222

23+
import { IExecutionPhaseOutput } from '../../jupyter/kernel';
2324
import './Output.css';
2425

2526
export type IOutputProps = {
@@ -40,9 +41,9 @@ export type IOutputProps = {
4041
showControl?: boolean;
4142
showEditor: boolean;
4243
showKernelProgressBar?: boolean;
44+
suppressCodeExecutionErrors?: boolean;
4345
toolbarPosition: 'up' | 'middle' | 'none';
44-
notifyOnComplete?: boolean;
45-
onCodeExecutionError?: (err : any) => void;
46+
onExecutionPhaseChanged? : (phaseOutput : IExecutionPhaseOutput) => void
4647
};
4748

4849
export const Output = (props: IOutputProps) => {
@@ -65,8 +66,8 @@ export const Output = (props: IOutputProps) => {
6566
showControl,
6667
showEditor,
6768
showKernelProgressBar = true,
68-
notifyOnComplete = false,
69-
onCodeExecutionError,
69+
suppressCodeExecutionErrors = false,
70+
onExecutionPhaseChanged,
7071
id: sourceId,
7172
toolbarPosition,
7273
} = props;
@@ -102,7 +103,7 @@ export const Output = (props: IOutputProps) => {
102103
}
103104
};
104105
if (id && kernel) {
105-
const adapter = propsAdapter ?? new OutputAdapter(id, kernel, outputs ?? [], model);
106+
const adapter = propsAdapter ?? new OutputAdapter(id, kernel, outputs ?? [], model,suppressCodeExecutionErrors);
106107
setAdapter(adapter);
107108
outputStore.setAdapter(id, adapter);
108109
if (model) {
@@ -126,7 +127,7 @@ export const Output = (props: IOutputProps) => {
126127
useEffect(() => {
127128
if (adapter) {
128129
if (autoRun) {
129-
adapter.execute(code, notifyOnComplete,onCodeExecutionError);
130+
adapter.execute(code,onExecutionPhaseChanged);
130131
}
131132
}
132133
}, [adapter]);
@@ -146,12 +147,12 @@ export const Output = (props: IOutputProps) => {
146147
const executeRequest = outputStore.getExecuteRequest(sourceId);
147148
useEffect(() => {
148149
if (adapter && executeRequest && executeRequest === id) {
149-
adapter.execute(code, notifyOnComplete,onCodeExecutionError);
150+
adapter.execute(code,onExecutionPhaseChanged);
150151
}
151152
}, [executeRequest, adapter]);
152153
useEffect(() => {
153154
if (adapter && executeTrigger > 0) {
154-
adapter.execute(code, notifyOnComplete,onCodeExecutionError);
155+
adapter.execute(code,onExecutionPhaseChanged);
155156
}
156157
}, [executeTrigger]);
157158
useEffect(() => {

packages/react/src/components/output/OutputAdapter.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
* MIT License
55
*/
66

7+
import {
8+
WIDGET_MIMETYPE,
9+
WidgetRenderer,
10+
} from '@jupyter-widgets/html-manager/lib/output_renderers';
11+
import { rendererFactory as javascriptRendererFactory } from '@jupyterlab/javascript-extension';
12+
import { rendererFactory as jsonRendererFactory } from '@jupyterlab/json-extension';
713
import { IOutput } from '@jupyterlab/nbformat';
8-
import { JSONObject } from '@lumino/coreutils';
914
import {
1015
IOutputAreaModel,
1116
OutputArea,
@@ -16,14 +21,10 @@ import {
1621
RenderMimeRegistry,
1722
standardRendererFactories,
1823
} from '@jupyterlab/rendermime';
19-
import { rendererFactory as jsonRendererFactory } from '@jupyterlab/json-extension';
20-
import { rendererFactory as javascriptRendererFactory } from '@jupyterlab/javascript-extension';
21-
import {
22-
WIDGET_MIMETYPE,
23-
WidgetRenderer,
24-
} from '@jupyter-widgets/html-manager/lib/output_renderers';
25-
import { requireLoader as loader } from '../../jupyter/ipywidgets/libembed-amd';
24+
import { JSONObject } from '@lumino/coreutils';
2625
import { ClassicWidgetManager } from '../../jupyter/ipywidgets/classic/manager';
26+
import { requireLoader as loader } from '../../jupyter/ipywidgets/libembed-amd';
27+
import { IExecutionPhaseOutput } from '../../jupyter/kernel';
2728
import { Kernel } from '../../jupyter/kernel/Kernel';
2829
import { execute } from './OutputExecutor';
2930

@@ -34,15 +35,18 @@ export class OutputAdapter {
3435
private _outputArea: OutputArea;
3536
private _rendermime: RenderMimeRegistry;
3637
private _iPyWidgetsClassicManager: ClassicWidgetManager;
38+
private _suppressCodeExecutionErrors: boolean;
3739

3840
public constructor(
3941
id: string,
4042
kernel?: Kernel,
4143
outputs?: IOutput[],
42-
outputAreaModel?: IOutputAreaModel
44+
outputAreaModel?: IOutputAreaModel,
45+
suppressCodeExecutionErrors: boolean = false
4346
) {
4447
this._id = id;
4548
this._kernel = kernel;
49+
this._suppressCodeExecutionErrors = suppressCodeExecutionErrors;
4650
this._renderers = standardRendererFactories.filter(
4751
factory => factory.mimeTypes[0] !== 'text/javascript'
4852
);
@@ -93,8 +97,7 @@ export class OutputAdapter {
9397

9498
public async execute(
9599
code: string,
96-
notifyOnComplete?: boolean,
97-
onCodeExecutionError?: (err: any) => void
100+
onExecutionPhaseChanged?: (phaseOutput: IExecutionPhaseOutput) => void
98101
) {
99102
if (this._kernel) {
100103
this.clear();
@@ -105,8 +108,8 @@ export class OutputAdapter {
105108
this._outputArea,
106109
this._kernel,
107110
metadata,
108-
notifyOnComplete,
109-
onCodeExecutionError
111+
this._suppressCodeExecutionErrors,
112+
onExecutionPhaseChanged
110113
);
111114
await done;
112115
}

packages/react/src/components/output/OutputExecutor.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* MIT License
55
*/
66

7-
import { JSONObject } from '@lumino/coreutils';
8-
import { KernelMessage } from '@jupyterlab/services';
97
import { OutputArea } from '@jupyterlab/outputarea';
8+
import { KernelMessage } from '@jupyterlab/services';
9+
import { JSONObject } from '@lumino/coreutils';
10+
import { IExecutionPhaseOutput } from '../../jupyter/kernel';
1011
import { Kernel } from './../../jupyter/kernel/Kernel';
1112

1213
/**
@@ -18,8 +19,8 @@ export async function execute(
1819
output: OutputArea,
1920
kernel: Kernel,
2021
metadata?: JSONObject,
21-
notifyOnComplete?: boolean,
22-
onCodeExecutionError?: (err: any) => void
22+
suppressCodeExecutionErrors: boolean = false,
23+
onExecutionPhaseChanged?: (phaseOutput: IExecutionPhaseOutput) => void
2324
): Promise<KernelMessage.IExecuteReplyMsg | undefined> {
2425
// Override the default for `stop_on_error`.
2526
let stopOnError = true;
@@ -33,9 +34,10 @@ export async function execute(
3334
const kernelExecutor = kernel.execute(code, {
3435
model: output.model,
3536
stopOnError,
36-
notifyOnComplete,
37-
onCodeExecutionError,
37+
suppressCodeExecutionErrors,
38+
onExecutionPhaseChanged,
3839
});
40+
3941
const future = kernelExecutor!.future;
4042
// TODO fix in upstream jupyterlab if possible...
4143
(output as any)._onIOPub = future!.onIOPub;

packages/react/src/examples/OutputWithErrorHandle.tsx

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)