/// <summary> /// Stops all the running channels for this kernel. /// This stops their event loops and joins their threads. /// </summary> public void StopChannels() { // Close down the threads polling for results if (StdInThread != null && StdInThread.IsAlive) { StdInThread.Interrupt(); } if (ShellThread != null && ShellThread.IsAlive) { ShellThread.Interrupt(); } if (IoPubThread != null && IoPubThread.IsAlive) { IoPubThread.Interrupt(); } // Stop all the channel sockets if (ShellChannel.IsAlive) { ShellChannel.Stop(); } if (IoPubChannel.IsAlive) { IoPubChannel.Stop(); } if (StdInChannel.IsAlive) { StdInChannel.Stop(); } if (HbChannel.IsAlive) { HbChannel.Stop(); } // Join any threads that existed if (StdInThread != null) { StdInThread.Join(); } if (ShellThread != null) { ShellThread.Join(); } if (IoPubThread != null) { IoPubThread.Join(); } // Clean up any threads StdInThread = null; ShellThread = null; IoPubThread = null; }
/// <summary> /// Starts the channels for this kernel. /// /// This will create the channels if they do not exist and then start /// them(their activity runs in a thread). If port numbers of 0 are /// being used(random ports) then you must first call /// :meth:`start_kernel`. If the channels have been stopped and you /// call this, :class:`RuntimeError` will be raised. /// </summary> /// <param name="shell"></param> /// <param name="iopub"></param> /// <param name="stdin"></param> /// <param name="hb"></param> public void StartChannels(bool shell = true, bool iopub = true, bool stdin = true, bool hb = true) { if (shell) { ShellChannel.Start(); ShellThread = new Thread(() => EventLoop(ShellChannel)) { Name = "Shell Channel" }; ShellThread.Start(); } if (iopub) { IoPubChannel.Start(); IoPubThread = new Thread(() => EventLoop(IoPubChannel)) { Name = "IoPub Channel" }; IoPubThread.Start(); } if (stdin) { StdInChannel.Start(); AllowStdin = true; StdInThread = new Thread(() => EventLoop(StdInChannel)) { Name = "StdIn Channel" }; StdInThread.Start(); } else { AllowStdin = false; } if (hb) { HbChannel.Start(); } // Now that the channels have started, collect the kernel information if (shell && ShellChannel.IsAlive) { KernelInfo(); } }
public Session(string filename) { this.filename = filename; engine_identity = System.Guid.NewGuid().ToString(); string json; if (this.filename != "") { json = File.ReadAllText(this.filename); config = decode(json); Console.Error.WriteLine(String.Format("config: {0}", config ["transport"])); Console.Error.WriteLine(String.Format("config: {0}", config ["ip"])); Console.Error.WriteLine(String.Format("config: {0}", config ["hb_port"])); } else { config = dict("key", System.Guid.NewGuid().ToString(), "signature_scheme", "hmac-sha256", "transport", "tcp", "ip", "127.0.0.1", "hb_port", "0", "shell_port", "0", "iopub_port", "0", "control_port", "0", "stdin_port", "0"); } auth = new Authorization(config ["key"].ToString(), config ["signature_scheme"].ToString()); hb_channel = new HeartBeatChannel(this, auth, config ["transport"].ToString(), config ["ip"].ToString(), config ["hb_port"].ToString()); shell_channel = new ShellChannel(this, auth, config ["transport"].ToString(), config ["ip"].ToString(), config ["shell_port"].ToString()); iopub_channel = new IOPubChannel(this, auth, config ["transport"].ToString(), config ["ip"].ToString(), config ["iopub_port"].ToString()); control_channel = new ControlChannel(this, auth, config ["transport"].ToString(), config ["ip"].ToString(), config ["control_port"].ToString()); stdin_channel = new StdInChannel(this, auth, config ["transport"].ToString(), config ["ip"].ToString(), config ["stdin_port"].ToString()); if (this.filename == "") { config ["hb_port"] = hb_channel.port; config ["shell_port"] = shell_channel.port; config ["iopub_port"] = iopub_channel.port; config ["control_port"] = control_channel.port; config ["stdin_port"] = stdin_channel.port; string kernelname = String.Format("kernel-{0}.json", System.Diagnostics.Process.GetCurrentProcess().Id); string ipython_config = ("{{\n" + " \"hb_port\": {0},\n" + " \"shell_port\": {1},\n" + " \"iopub_port\": {2},\n" + " \"control_port\": {3},\n" + " \"stdin_port\": {4},\n" + " \"ip\": \"{5}\",\n" + " \"signature_scheme\": \"{6}\",\n" + " \"key\": \"{7}\",\n" + " \"transport\": \"{8}\"\n" + "}}"); ipython_config = String.Format(ipython_config, config ["hb_port"], config ["shell_port"], config ["iopub_port"], config ["control_port"], config ["stdin_port"], config ["ip"], config ["signature_scheme"], config ["key"], config ["transport"]); System.IO.StreamWriter sw = new System.IO.StreamWriter(this.filename); sw.Write(ipython_config); sw.Close(); Console.Error.WriteLine("IPython config file written to:"); Console.Error.WriteLine(" \"{0}\"", this.filename); Console.Error.WriteLine("To exit, you will have to explicitly quit this process, by either sending"); Console.Error.WriteLine("\"quit\" from a client, or using Ctrl-\\ in UNIX-like environments."); Console.Error.WriteLine("To read more about this, see https://github.com/ipython/ipython/issues/2049"); Console.Error.WriteLine("To connect another client to this kernel, use:"); Console.Error.WriteLine(" --existing {0} --profile calico", kernelname); } }