Skip to content

Commit c702f1b

Browse files
authored
Merge pull request #103 from SpencerPark/busy-idle
Wrap all shell request/reply with busy-idle. Fix #99
2 parents 57ad008 + 873dcc7 commit c702f1b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

kernel.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,17 @@ func prepareSockets(connInfo ConnectionInfo) (SocketGroup, error) {
243243

244244
// handleShellMsg responds to a message on the shell ROUTER socket.
245245
func handleShellMsg(ir *interp.Interp, receipt msgReceipt) {
246+
// Tell the front-end that the kernel is working and when finished notify the
247+
// front-end that the kernel is idle again.
248+
if err := receipt.PublishKernelStatus(kernelBusy); err != nil {
249+
log.Printf("Error publishing kernel status 'busy': %v\n", err)
250+
}
251+
defer func() {
252+
if err := receipt.PublishKernelStatus(kernelIdle); err != nil {
253+
log.Printf("Error publishing kernel status 'idle': %v\n", err)
254+
}
255+
}()
256+
246257
switch receipt.Msg.Header.MsgType {
247258
case "kernel_info_request":
248259
if err := sendKernelInfo(receipt); err != nil {
@@ -297,17 +308,6 @@ func handleExecuteRequest(ir *interp.Interp, receipt msgReceipt) error {
297308
content := make(map[string]interface{})
298309
content["execution_count"] = ExecCounter
299310

300-
// Tell the front-end that the kernel is working and when finished notify the
301-
// front-end that the kernel is idle again.
302-
if err := receipt.PublishKernelStatus(kernelBusy); err != nil {
303-
log.Printf("Error publishing kernel status 'busy': %v\n", err)
304-
}
305-
defer func() {
306-
if err := receipt.PublishKernelStatus(kernelIdle); err != nil {
307-
log.Printf("Error publishing kernel status 'idle': %v\n", err)
308-
}
309-
}()
310-
311311
// Tell the front-end what the kernel is about to execute.
312312
if err := receipt.PublishExecutionInput(ExecCounter, code); err != nil {
313313
log.Printf("Error publishing execution input: %v\n", err)

0 commit comments

Comments
 (0)