-
-
Notifications
You must be signed in to change notification settings - Fork 551
/
kernels.ts
134 lines (118 loc) Β· 3.74 KB
/
kernels.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { ChildProcess } from "child_process";
import * as Immutable from "immutable";
import { Observable, Subject } from "rxjs";
import { KernelId, SessionId } from "../ids";
import { HostRef, KernelRef } from "../refs";
import { KernelInfo } from "./kernel-info";
// See #3427. This represents the kernel early in the launch process.
// With a bit more work we could probably drop this and just use either
// Local or RemoteKernelProps as our initial representation of the kernel,
// deriving local-vs-remote from known sources of truth about kernels.
export interface KernelNotStartedProps {
kernelSpecName?: string | null;
status?: string | null;
// The following properties are not known immediately at the start of
// launch; they are just included to keep Flow happy and minimize the
// impact of this likely-to-be-deleted type.
type: "unknown";
cwd: ".";
channels: Subject<any>;
info?: KernelInfo | null;
}
export type KernelNotStartedRecord = Immutable.RecordOf<KernelNotStartedProps>;
export const makeKernelNotStartedRecord = Immutable.Record<
KernelNotStartedProps
>({
kernelSpecName: null,
status: null,
type: "unknown",
cwd: ".",
channels: new Subject(),
info: null
});
export enum KernelStatus {
/** Kernel is currently executing code. */
Busy = "busy",
/** Kernel is currently not executing code. */
Idle = "idle",
/** Kernel process is being launched. */
Starting = "starting",
/** Kernel is being shut down. */
ShuttingDown = "shutting down",
/** Kernel is restarting. */
Restarting = "restarting",
/** Kernel's current execution process has been interrupted. */
Interrupted = "interrupted",
/** Kernel is not connected to current notebook. */
NotConnected = "not connected"
}
export interface LocalKernelProps {
kernelSpecName?: string | null;
info?: KernelInfo | null;
hostRef?: HostRef | null;
lastActivity?: Date | null;
channels: Subject<any>;
cwd: string;
// Canonically: idle, busy, starting
// Xref: http://jupyter-client.readthedocs.io/en/stable/messaging.html#kernel-status
//
// We also use this for other bits of lifecycle, including: launching,
// shutting down, not connected.
status?: string | null;
type: "zeromq";
spawn?: ChildProcess | null;
connectionFile?: string | null;
}
export const makeLocalKernelRecord = Immutable.Record<LocalKernelProps>({
type: "zeromq",
cwd: ".",
info: null,
kernelSpecName: null,
hostRef: null,
lastActivity: null,
channels: new Subject(),
status: null,
spawn: null,
connectionFile: null
});
export type LocalKernelRecord = Immutable.RecordOf<LocalKernelProps>;
export interface RemoteKernelProps {
kernelSpecName?: string | null;
info?: KernelInfo | null;
hostRef?: HostRef | null;
lastActivity?: Date | null;
channels: Subject<any>;
cwd: string;
// Canonically: idle, busy, starting
// Xref: http://jupyter-client.readthedocs.io/en/stable/messaging.html#kernel-status
//
// We also use this for other bits of lifecycle, including: launching,
// shutting down, not connected.
status?: string | null;
type: "websocket";
sessionId?: SessionId | null;
id?: KernelId | null;
}
export const makeRemoteKernelRecord = Immutable.Record<RemoteKernelProps>({
type: "websocket",
info: null,
cwd: ".",
id: null,
kernelSpecName: null,
hostRef: null,
lastActivity: null,
channels: new Subject(),
sessionId: null,
status: null
});
export type RemoteKernelRecord = Immutable.RecordOf<RemoteKernelProps>;
export type KernelRecord =
| KernelNotStartedRecord
| LocalKernelRecord
| RemoteKernelRecord;
export interface KernelsRecordProps {
byRef: Immutable.Map<KernelRef, KernelRecord>;
}
export const makeKernelsRecord = Immutable.Record<KernelsRecordProps>({
byRef: Immutable.Map()
});