Skip to content

Commit 50fe121

Browse files
sok82Sergey Kadnikov
andauthored
314, fixed assigning execution phase for stream output (#315)
Co-authored-by: Sergey Kadnikov <skadnikov@seeneco.ru>
1 parent 90b6ddc commit 50fe121

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

packages/react/src/examples/OutputWithMonitoring.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@ const OUTPUTS_2: IOutput[] = [
3535
const SOURCE_ID_3 = 'output-id-3';
3636
const SOURCE_3 = 'a = 5';
3737

38+
const SOURCE_ID_4 = 'output-id-4';
39+
const SOURCE_4 =
40+
"import warnings; warnings.warn('This is a warning message'); print('See warning in output!')";
41+
42+
const SOURCE_ID_5 = 'output-id-5';
43+
const SOURCE_5 = 'print(2+2)';
44+
3845
const OutputWithMonitoring = ({
3946
title,
4047
id,
4148
code,
4249
output,
4350
}: {
44-
title: string,
51+
title: string;
4552
id: string;
4653
code: string;
4754
output?: IOutput[];
@@ -79,6 +86,14 @@ const OutputWithMonitoring = ({
7986
JSON.stringify(phaseOutput.outputModel?.toJSON()),
8087
]);
8188
break;
89+
case ExecutionPhase.completed_with_warning:
90+
setExecutionLog(executionLog => [
91+
...executionLog,
92+
new Date().toISOString() +
93+
' EXECUTION PHASE - COMPLETED_WITH_WARNING and output ' +
94+
JSON.stringify(phaseOutput.outputModel?.toJSON()),
95+
]);
96+
break;
8297
}
8398
};
8499

@@ -150,5 +165,19 @@ root.render(
150165
id={SOURCE_ID_3}
151166
code={SOURCE_3}
152167
/>
168+
169+
<OutputWithMonitoring
170+
title="Code generating warning"
171+
key="4"
172+
id={SOURCE_ID_4}
173+
code={SOURCE_4}
174+
/>
175+
176+
<OutputWithMonitoring
177+
title="Code with stream output"
178+
key="5"
179+
id={SOURCE_ID_5}
180+
code={SOURCE_5}
181+
/>
153182
</Jupyter>
154183
);

packages/react/src/jupyter/kernel/KernelExecutor.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,26 @@ export class KernelExecutor {
190190
.getState()
191191
.getExecutionPhase(this._kernelConnection.id);
192192
if (currentPhase !== ExecutionPhase.completed_with_error) {
193+
// Check if we have warning in output list
194+
let hasWarning = false;
195+
for (let i = 0; i < this.model.length; i++) {
196+
const modelItem = this.model.get(i);
197+
if (
198+
modelItem.type === 'stream' &&
199+
modelItem.toJSON().name === 'stderr'
200+
) {
201+
hasWarning = true;
202+
break;
203+
}
204+
}
205+
const targetPhase = hasWarning
206+
? ExecutionPhase.completed_with_warning
207+
: ExecutionPhase.completed;
193208
kernelsStore
194209
.getState()
195-
.setExecutionPhase(
196-
this._kernelConnection.id,
197-
ExecutionPhase.completed
198-
);
210+
.setExecutionPhase(this._kernelConnection.id, targetPhase);
199211
this._executionPhaseChanged.emit({
200-
executionPhase: ExecutionPhase.completed,
212+
executionPhase: targetPhase,
201213
outputModel: this._model,
202214
});
203215
}
@@ -307,6 +319,11 @@ export class KernelExecutor {
307319
this._modelChanged.emit(this._model);
308320
break;
309321
case 'stream':
322+
this._outputs.push(message.content as IStream);
323+
this._outputsChanged.emit(this._outputs);
324+
this._model.add(output);
325+
this._modelChanged.emit(this._model);
326+
break;
310327
case 'error':
311328
this._outputs.push(message.content as IStream);
312329
this._outputsChanged.emit(this._outputs);

packages/react/src/jupyter/kernel/KernelState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export enum ExecutionPhase {
1313
running = 'RUNNING',
1414
completed = 'COMPLETED',
1515
completed_with_error = 'COMPLETED_WITH_ERROR',
16+
completed_with_warning = 'COMPLETED_WITH_WARNING',
1617
}
1718

1819
export type IKernelState = {

packages/react/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const ENTRY =
4646
// './src/examples/NotebookColorMode';
4747
// './src/examples/NotebookKernelChange';
4848
// './src/examples/NotebookLite';
49-
'./src/examples/NotebookMutations';
49+
// './src/examples/NotebookMutations';
5050
// './src/examples/NotebookNbformat';
5151
// './src/examples/NotebookNbformatChange';
5252
// './src/examples/NotebookNoContext';
@@ -60,7 +60,7 @@ const ENTRY =
6060
// './src/examples/NotebookURL';
6161
// './src/examples/ObservableHQ';
6262
// './src/examples/Output';
63-
// './src/examples/OutputWithMonitoring';
63+
'./src/examples/OutputWithMonitoring';
6464
// './src/examples/Outputs';
6565
// './src/examples/Plotly';
6666
// './src/examples/RunningSessions';

0 commit comments

Comments
 (0)