Skip to content

Commit ba8719c

Browse files
jmcpherswesm
authored andcommitted
Merged PR posit-dev/positron-python#221: Provide a reason for runtime exits
Merge pull request #221 from posit-dev/feature/runtime-exit-reason Provide a reason for runtime exits -------------------- Commit message for posit-dev/positron-python@e603579: provide a reason for runtime exits Authored-by: Jonathan McPherson <[email protected]> Signed-off-by: Jonathan McPherson <[email protected]>
1 parent 2d3895c commit ba8719c

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

extensions/positron-python/positron-dts/positron.d.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,53 @@ declare module 'positron' {
126126
Continue = 'continue',
127127
}
128128

129+
/**
130+
* Possible reasons a language runtime could exit.
131+
*/
132+
export enum RuntimeExitReason {
133+
/** The runtime exited because it could not start correctly. */
134+
StartupFailed = 'startupFailed',
135+
136+
/** The runtime is shutting down at the request of the user. */
137+
Shutdown = 'shutdown',
138+
139+
/** The runtime exited because it was forced to quit. */
140+
ForcedQuit = 'forcedQuit',
141+
142+
/** The runtime is exiting in order to restart. */
143+
Restart = 'restart',
144+
145+
/** The runtime exited because of an error, most often a crash. */
146+
Error = 'error',
147+
148+
/**
149+
* The runtime exited for an unknown reason. This typically means that
150+
* it exited unexpectedly but with a normal exit code (0).
151+
*/
152+
Unknown = 'unknown',
153+
}
154+
155+
/**
156+
* LanguageRuntimeExit is an interface that defines an event occurring when a
157+
* language runtime exits.
158+
*/
159+
export interface LanguageRuntimeExit {
160+
/**
161+
* The process exit code, if the runtime is backed by a process. If the
162+
* runtime is not backed by a process, this should just be 0 for a
163+
* succcessful exit and 1 for an error.
164+
*/
165+
exit_code: number;
166+
167+
/**
168+
* The reason the runtime exited.
169+
*/
170+
reason: RuntimeExitReason;
171+
172+
/** The exit message, if any. */
173+
message: string;
174+
}
175+
129176
/**
130177
* LanguageRuntimeMessage is an interface that defines an event occurring in a
131178
* language runtime, such as outputting text or plots.
@@ -444,6 +491,9 @@ declare module 'positron' {
444491
/** An object that emits the current state of the runtime */
445492
onDidChangeRuntimeState: vscode.Event<RuntimeState>;
446493

494+
/** An object that emits an event when the user's session ends and the runtime exits */
495+
onDidEndSession: vscode.Event<LanguageRuntimeExit>;
496+
447497
/** Execute code in the runtime */
448498
execute(code: string,
449499
id: string,

extensions/positron-python/src/client/positron/runtime.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export class PythonRuntime implements positron.LanguageRuntime, vscode.Disposabl
3737
/** The emitter for language runtime state changes */
3838
private _stateEmitter = new vscode.EventEmitter<positron.RuntimeState>();
3939

40+
/** The emitter for language runtime exits */
41+
private _exitEmitter = new vscode.EventEmitter<positron.LanguageRuntimeExit>();
42+
4043
/** The Jupyter Adapter extension API */
4144
private adapterApi?: JupyterAdapterApi;
4245

@@ -53,6 +56,7 @@ export class PythonRuntime implements positron.LanguageRuntime, vscode.Disposabl
5356
this._queue = new PQueue({ concurrency: 1 });
5457
this.onDidReceiveRuntimeMessage = this._messageEmitter.event;
5558
this.onDidChangeRuntimeState = this._stateEmitter.event;
59+
this.onDidEndSession = this._exitEmitter.event;
5660

5761
this.onDidChangeRuntimeState((state) => {
5862
this.onStateChange(state);
@@ -63,6 +67,8 @@ export class PythonRuntime implements positron.LanguageRuntime, vscode.Disposabl
6367

6468
onDidChangeRuntimeState: vscode.Event<positron.RuntimeState>;
6569

70+
onDidEndSession: vscode.Event<positron.LanguageRuntimeExit>;
71+
6672
execute(
6773
code: string,
6874
id: string,
@@ -244,6 +250,9 @@ export class PythonRuntime implements positron.LanguageRuntime, vscode.Disposabl
244250
kernel.onDidReceiveRuntimeMessage((message) => {
245251
this._messageEmitter.fire(message);
246252
});
253+
kernel.onDidEndSession((exit) => {
254+
this._exitEmitter.fire(exit);
255+
});
247256
return kernel;
248257
}
249258

0 commit comments

Comments
 (0)