MCPcopy Index your code
hub / github.com/gopherdata/gophernotes / runKernel

Function runKernel

kernel.go:127–243  ·  view source on GitHub ↗

runKernel is the main entry point to start the kernel.

(connectionFile string)

Source from the content-addressed store, hash-verified

125
126// runKernel is the main entry point to start the kernel.
127func runKernel(connectionFile string) {
128
129 // Create a new interpreter for evaluating notebook code.
130 ir := interp.New()
131
132 // Throw out the error/warning messages that gomacro outputs writes to these streams.
133 ir.Comp.Stdout = ioutil.Discard
134 ir.Comp.Stderr = ioutil.Discard
135
136 // Inject the "display" package to render HTML, JSON, PNG, JPEG, SVG... from interpreted code
137 // maybe a dot-import is easier to use?
138 display := importPackage(ir, "display", "display")
139
140 // Inject the stub "Display" function. declare a variable
141 // instead of a function, because we want to later change
142 // its value to the closure that holds a reference to msgReceipt
143 ir.DeclVar("Display", nil, stubDisplay)
144
145 // Parse the connection info.
146 var connInfo ConnectionInfo
147
148 connData, err := ioutil.ReadFile(connectionFile)
149 if err != nil {
150 log.Fatal(err)
151 }
152
153 if err = json.Unmarshal(connData, &connInfo); err != nil {
154 log.Fatal(err)
155 }
156
157 // Set up the ZMQ sockets through which the kernel will communicate.
158 sockets, err := prepareSockets(connInfo)
159 if err != nil {
160 log.Fatal(err)
161 }
162
163 // TODO connect all channel handlers to a WaitGroup to ensure shutdown before returning from runKernel.
164
165 // Start up the heartbeat handler.
166 startHeartbeat(sockets.HBSocket, &sync.WaitGroup{})
167
168 // TODO gracefully shutdown the heartbeat handler on kernel shutdown by closing the chan returned by startHeartbeat.
169
170 type msgType struct {
171 Msg zmq4.Msg
172 Err error
173 }
174
175 var (
176 shell = make(chan msgType)
177 stdin = make(chan msgType)
178 ctl = make(chan msgType)
179 quit = make(chan int)
180 )
181
182 defer close(quit)
183 poll := func(msgs chan msgType, sck zmq4.Socket) {
184 defer close(msgs)

Callers 2

runTestFunction · 0.85
mainFunction · 0.85

Calls 6

initRenderersMethod · 0.95
handleShellMsgMethod · 0.95
importPackageFunction · 0.85
prepareSocketsFunction · 0.85
startHeartbeatFunction · 0.85
WireMsgToComposedMsgFunction · 0.85

Tested by 1

runTestFunction · 0.68