func RunKernel(connectionFile string, logwriter io.Writer) {

	logger = log.New(logwriter, "gophernotes ", log.LstdFlags)

	// Set up the "Session" with the replpkg.
	SetupExecutionEnvironment()

	var connInfo ConnectionInfo
	bs, err := ioutil.ReadFile(connectionFile)
	if err != nil {
		log.Fatalln(err)
	}
	if err = json.Unmarshal(bs, &connInfo); err != nil {
		log.Fatalln(err)
	}
	logger.Printf("%+v\n", connInfo)

	// Set up the ZMQ sockets through which the kernel will communicate.
	sockets, err := PrepareSockets(connInfo)
	if err != nil {
		log.Fatalln(err)
	}

	pi := zmq.PollItems{
		zmq.PollItem{Socket: sockets.ShellSocket, Events: zmq.POLLIN},
		zmq.PollItem{Socket: sockets.StdinSocket, Events: zmq.POLLIN},
		zmq.PollItem{Socket: sockets.ControlSocket, Events: zmq.POLLIN},
	}

	// Start a message receiving loop.
	var msgparts [][]byte
	for {
		if _, err = zmq.Poll(pi, -1); err != nil {
			log.Fatalln(err)
		}
		switch {
		case pi[0].REvents&zmq.POLLIN != 0: // shell socket
			msgparts, _ = pi[0].Socket.RecvMultipart(0)
			msg, ids, err := WireMsgToComposedMsg(msgparts, sockets.Key)
			if err != nil {
				log.Println(err)
				return
			}
			HandleShellMsg(MsgReceipt{msg, ids, sockets})
		case pi[1].REvents&zmq.POLLIN != 0: // stdin socket - not implemented.
			pi[1].Socket.RecvMultipart(0)
		case pi[2].REvents&zmq.POLLIN != 0: // control socket - treat like shell socket.
			msgparts, err = pi[2].Socket.RecvMultipart(0)
			if err != nil {
				log.Println(err)
				return
			}
			msg, ids, err := WireMsgToComposedMsg(msgparts, sockets.Key)
			if err != nil {
				log.Println(err)
				return
			}
			HandleShellMsg(MsgReceipt{msg, ids, sockets})
		}
	}
}
// RunKernel is the main entry point to start the kernel.
RunKernel is the main entry point to start the kernel.
// RunKernel is the main entry point to start the kernel .
func RunKernel(connectionFile string, logwriter io.Writer) {
	logger = log.New(logwriter, "gophernotes ", log.LstdFlags)
	SetupExecutionEnvironment()
	var connInfo ConnectionInfo
	bs, err := ioutil.ReadFile(connectionFile)
	if err != nil {
		log.Fatalln(err)
	}
	if err = json.Unmarshal(bs, &connInfo); err != nil {
		log.Fatalln(err)
	}
	logger.Printf("%+v\n", connInfo)
	sockets, err := PrepareSockets(connInfo)
	if err != nil {
		log.Fatalln(err)
	}
	pi := zmq.PollItems{
		zmq.PollItem{Socket: sockets.ShellSocket, Events: zmq.POLLIN},
		zmq.PollItem{Socket: sockets.StdinSocket, Events: zmq.POLLIN},
		zmq.PollItem{Socket: sockets.ControlSocket, Events: zmq.POLLIN},
	}
	var msgparts [][]byte
	for {
		if _, err = zmq.Poll(pi, -1); err != nil {
			log.Fatalln(err)
		}
		switch {
		case pi[0].REvents&zmq.POLLIN != 0: 
			msgparts, _ = pi[0].Socket.RecvMultipart(0)
			msg, ids, err := WireMsgToComposedMsg(msgparts, sockets.Key)
			if err != nil {
				log.Println(err)
				return
			}
			HandleShellMsg(MsgReceipt{msg, ids, sockets})
		case pi[1].REvents&zmq.POLLIN != 0: 
			pi[1].Socket.RecvMultipart(0)
		case pi[2].REvents&zmq.POLLIN != 0: 
			msgparts, err = pi[2].Socket.RecvMultipart(0)
			if err != nil {
				log.Println(err)
				return
			}
			msg, ids, err := WireMsgToComposedMsg(msgparts, sockets.Key)
			if err != nil {
				log.Println(err)
				return
			}
			HandleShellMsg(MsgReceipt{msg, ids, sockets})
		}
	}
}
func RunKernel ( connectionFile string , logwriter io . Writer ) { logger = log . New ( logwriter , " " , log . LstdFlags ) SetupExecutionEnvironment ( ) var connInfo ConnectionInfo bs , err := ioutil . ReadFile ( connectionFile ) if err != nil { log . Fatalln ( err ) } if err = json . Unmarshal ( bs , & connInfo ) ; err != nil { log . Fatalln ( err ) } logger . Printf ( " \n " , connInfo ) sockets , err := PrepareSockets ( connInfo ) if err != nil { log . Fatalln ( err ) } pi := zmq . PollItems { zmq . PollItem { Socket : sockets . ShellSocket , Events : zmq . POLLIN } , zmq . PollItem { Socket : sockets . StdinSocket , Events : zmq . POLLIN } , zmq . PollItem { Socket : sockets . ControlSocket , Events : zmq . POLLIN } , } var msgparts [ ] [ ] byte for { if _ , err = zmq . Poll ( pi , - 1 ) ; err != nil { log . Fatalln ( err ) } switch { case pi [ 0 ] . REvents & zmq . POLLIN != 0 : msgparts , _ = pi [ 0 ] . Socket . RecvMultipart ( 0 ) msg , ids , err := WireMsgToComposedMsg ( msgparts , sockets . Key ) if err != nil { log . Println ( err ) return } HandleShellMsg ( MsgReceipt { msg , ids , sockets } ) case pi [ 1 ] . REvents & zmq . POLLIN != 0 : pi [ 1 ] . Socket . RecvMultipart ( 0 ) case pi [ 2 ] . REvents & zmq . POLLIN != 0 : msgparts , err = pi [ 2 ] . Socket . RecvMultipart ( 0 ) if err != nil { log . Println ( err ) return } msg , ids , err := WireMsgToComposedMsg ( msgparts , sockets . Key ) if err != nil { log . Println ( err ) return } HandleShellMsg ( MsgReceipt { msg , ids , sockets } ) } } }
RunKernel is the main entry point to start the kernel.
RunKernel is the main entry point to start the kernel .
// Set up the "Session" with the replpkg. // Set up the ZMQ sockets through which the kernel will communicate. // Start a message receiving loop. // shell socket // stdin socket - not implemented. // control socket - treat like shell socket.