Skip to content

Commit

Permalink
Add Multiple Kernel Support!
Browse files Browse the repository at this point in the history
  • Loading branch information
prasunanand committed Dec 18, 2024
1 parent 37252e0 commit 11c6ac7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
16 changes: 9 additions & 7 deletions kernel/kernel_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ func isLocalIP(ip string) bool {
*********************************************************************/

func (km *KernelManager) asyncLaunchKernel(kernelCmd []string, kw map[string]interface{}) {
// km.Provisioner.launchKernel(kernelCmd)
log.Info().Msgf("kw : %s", kw)
log.Info().Msgf("cmd : %s", kernelCmd)
// log.Info().Msgf("kw : %s", kw)
// log.Info().Msgf("cmd : %s", kernelCmd)

ConnectionInfo := km.Provisioner.LaunchKernel(kernelCmd, kw)
ConnectionInfo := km.Provisioner.LaunchKernel(kernelCmd, kw, km.ConnectionFile)
log.Info().Msgf("connectionInfo: %s", ConnectionInfo)
}

Expand All @@ -105,8 +104,8 @@ func (km *KernelManager) preLaunch() map[string]interface{} {
if km.ConnectionInfo.Transport == "tcp" && !isLocalIP(km.ConnectionInfo.IP) {
log.Info().Msg("Can only launch a kernel on a local interface.")
}
log.Info().Msgf("cache ports: %t", km.CachePorts)
log.Info().Msgf("km.Provisioner.PortsCached %t", km.Provisioner.PortsCached)
// log.Info().Msgf("cache ports: %t", km.CachePorts)
// log.Info().Msgf("km.Provisioner.PortsCached %t", km.Provisioner.PortsCached)

if km.CachePorts && !km.Provisioner.PortsCached {
km.ConnectionInfo.ShellPort, _ = findAvailablePort()
Expand All @@ -116,7 +115,10 @@ func (km *KernelManager) preLaunch() map[string]interface{} {
km.ConnectionInfo.ControlPort, _ = findAvailablePort()
log.Info().Msgf("connectionInfo : %+v", km.ConnectionInfo)
}
km.writeConnectionFile("kernelConnection.json")
log.Info().Msgf("km.ConnectionFile : %+v", km.ConnectionFile)

km.writeConnectionFile(km.ConnectionFile)
// km.writeConnectionFile("kernelConnection.json")

kernelCmd := km.formatKernelCmd()
log.Info().Msgf("kernel cmd is %s", kernelCmd)
Expand Down
2 changes: 1 addition & 1 deletion kernel/kernel_supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func CwdForPath(path string) string {
}

func createKernelManager(kernelName string, kernelId string) (KernelManager, string, string) {
connectionDir := ""
connectionDir := "/tmp/"
kernelName = "python3" // note this is default kernel Name
connectionFile := filepath.Join(connectionDir, "kernel-"+kernelId[:6]+".json")
km := KernelManager{
Expand Down
4 changes: 2 additions & 2 deletions kernel/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/rs/zerolog/log"
)

func LaunchKernel(kernelCmd []string, kw map[string]interface{}) *os.Process {
func LaunchKernel(kernelCmd []string, kw map[string]interface{}, connFile string) *os.Process {

cmd := exec.Command("/usr/bin/python3", "-m", "ipykernel_launcher", "-f", "kernelConnection.json") // "--debug"
cmd := exec.Command("/usr/bin/python3", "-m", "ipykernel_launcher", "-f", connFile) // "--debug"

// Create pipes for standard input, output, and error
stdin, err := cmd.StdinPipe()
Expand Down
4 changes: 2 additions & 2 deletions kernel/provisioner/local_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type LocalProvisioner struct {
PortsCached bool
}

func (provisioner *LocalProvisioner) LaunchKernel(kernelCmd []string, kw map[string]interface{}) KernelConnectionInfo {
process := launcher.LaunchKernel(kernelCmd, kw)
func (provisioner *LocalProvisioner) LaunchKernel(kernelCmd []string, kw map[string]interface{}, connFile string) KernelConnectionInfo {
process := launcher.LaunchKernel(kernelCmd, kw, connFile)
provisioner.Pid = process.Pid
log.Info().Msgf("kernel launched with pid: %d", process.Pid)
return provisioner.ConnectionInfo
Expand Down
2 changes: 1 addition & 1 deletion kernel/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func findAvailablePort() (int, error) {
if portExists(port) {
continue
}
log.Info().Msgf("check port %d", port)
// log.Info().Msgf("check port %d", port)
l, err := net.Listen("tcp", ":"+strconv.Itoa(port))
if err == nil {
currentlyUsedPorts = append(currentlyUsedPorts, port)
Expand Down
2 changes: 1 addition & 1 deletion ui/src/ide/editor/notebook/NotebookEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default function NotebookEditor(props) {
useEffect(() => {
if (props.data.load_required === true) {
FetchFileData(props.data.path);
// const session = startASession(props.data.path, props.data.name, props.data.type);
const session = startASession(props.data.path, props.data.name, props.data.type);
}
}, [props.data]);

Expand Down

0 comments on commit 11c6ac7

Please sign in to comment.