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

Method handleExecuteRequest

kernel.go:435–537  ·  view source on GitHub ↗

handleExecuteRequest runs code from an execute_request method, and sends the various reply messages.

(receipt msgReceipt)

Source from the content-addressed store, hash-verified

433// handleExecuteRequest runs code from an execute_request method,
434// and sends the various reply messages.
435func (kernel *Kernel) handleExecuteRequest(receipt msgReceipt) error {
436
437 // Extract the data from the request.
438 reqcontent := receipt.Msg.Content.(map[string]interface{})
439 code := reqcontent["code"].(string)
440 silent := reqcontent["silent"].(bool)
441
442 if !silent {
443 ExecCounter++
444 }
445
446 // Prepare the map that will hold the reply content.
447 content := make(map[string]interface{})
448 content["execution_count"] = ExecCounter
449
450 // Tell the front-end what the kernel is about to execute.
451 if err := receipt.PublishExecutionInput(ExecCounter, code); err != nil {
452 log.Printf("Error publishing execution input: %v\n", err)
453 }
454
455 // Redirect the standard out from the REPL.
456 oldStdout := os.Stdout
457 rOut, wOut, err := os.Pipe()
458 if err != nil {
459 return err
460 }
461 os.Stdout = wOut
462
463 // Redirect the standard error from the REPL.
464 oldStderr := os.Stderr
465 rErr, wErr, err := os.Pipe()
466 if err != nil {
467 return err
468 }
469 os.Stderr = wErr
470
471 var writersWG sync.WaitGroup
472 writersWG.Add(2)
473
474 jupyterStdOut := JupyterStreamWriter{StreamStdout, &receipt}
475 jupyterStdErr := JupyterStreamWriter{StreamStderr, &receipt}
476 outerr := OutErr{&jupyterStdOut, &jupyterStdErr}
477
478 // Forward all data written to stdout/stderr to the front-end.
479 go func() {
480 defer writersWG.Done()
481 io.Copy(&jupyterStdOut, rOut)
482 }()
483
484 go func() {
485 defer writersWG.Done()
486 io.Copy(&jupyterStdErr, rErr)
487 }()
488
489 // inject the actual "Display" closure that displays multimedia data in Jupyter
490 ir := kernel.ir
491 displayPlace := ir.ValueOf("Display")
492 displayPlace.Set(xreflect.ValueOf(receipt.PublishDisplayData))

Callers 1

handleShellMsgMethod · 0.95

Calls 7

autoRenderResultsMethod · 0.95
doEvalFunction · 0.85
PublishExecutionInputMethod · 0.80
ErrorMethod · 0.80
PublishExecutionErrorMethod · 0.80
ReplyMethod · 0.80

Tested by

no test coverage detected