-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Would like to extend basekernel to talk to an IPython Kernel #14
Comments
Hello @phpmaps, this was a use case I didn't consider but makes perfect sense for inclusion in this project even if just for use in testing. The current machinery only considers that the jvm is running the server side of the jupyter connection which is why you aren't having any luck getting it to work as a controller. The functionality you are describing is the job of the All of the protocol messages are already nicely wrapped because we need to receive them so extending some functionality to create a If you would like to take a stab at it, I would be happy to review a PR. Otherwise I've got a midterm on Thursday after which I can start on this. |
Alright I've got something that is essentially working. It was bigger than I expected and so it turned into it's own project. https://github.com/SpencerPark/jupyter-jvm-client. The documentation is severely lacking at the moment but hopefully I can take care of that soon as well as getting something published. If you are feeling adventurous the gist of it is that you need to create a |
@SpencerPark - very cool. something interesting has come up. want to email me [email protected]? |
@phpmaps just sent an email and posting here to keep track but of course the discussion can continue via email. |
Hi I Just wonder do you have any working example which shown connecting to remote kernel and executing code. |
@jits023 I'm in the middle of moving things around (see #18) which includes bringing the client in here and also writing some documentation for how to use everything include what everything does. That restructure is going to bring a major version bump but mostly because of package changes. I'm also hoping to get the client published along with some api packages. The client project currently supports connecting directly via the zmq channels but I'm also hoping to transparently support the gateway protocol as well. If that is what you're looking for it will have to wait. To connect to a kernel that you have a connection file for ( $ jupyter kernel --kernel=python3
[KernelApp] Starting kernel 'python3'
[KernelApp] Connection file: C:\Users\Spencer\AppData\Roaming\jupyter\runtime\kernel-275c7c13-a8f6-4af7-9d8c-b270bd79ebe1.json
[KernelApp] To connect a client: --existing kernel-275c7c13-a8f6-4af7-9d8c-b270bd79ebe1.json The following should work (if using the current build on the import io.github.spencerpark.jupyter.api.KernelConnectionProperties;
import io.github.spencerpark.jupyter.api.display.mime.MIMEType;
import io.github.spencerpark.jupyter.client.channels.JupyterClientConnection;
import io.github.spencerpark.jupyter.comm.DefaultCommManager;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
//...
Path path = Paths.get("C:\\Users\\Spencer\\AppData\\Roaming\\jupyter\\runtime\\kernel-275c7c13-a8f6-4af7-9d8c-b270bd79ebe1.json");
KernelConnectionProperties props = KernelConnectionProperties.parse(new String(Files.readAllBytes(path), StandardCharsets.UTF_8));
JupyterClientConnection connection = new JupyterClientConnection(props);
connection.connect();
RemoteJupyterKernel kernel = new RemoteJupyterKernel(new DefaultCommManager());
kernel.connect(this.connection);
try {
ExecutionResult result = this.kernel.eval("print('Hello from the python kernel!')\n10", IOProcider.STD);
if (result.hasValue())
System.out.printf("Out [%d]: %s%n", result.getExecutionCount(), result.getValue().getData(MIMEType.TEXT_PLAIN));
} catch (JupyterPublishedException e) {
// Code executed threw this exception
System.out.printf("%s: %s%n", e.getPublishedError().getErrorName(), e.getPublishedError().getErrorMessage());
} catch (JupyterReplyException e) {
// Kernel internal error caused this exception
System.out.printf("%s %s: %s%n", e.getReply().getStatus(), e.getReply().getErrorName(), e.getReply().getErrorMessage());
} I would appreciate any feedback on the API if you get a chance to use it :) |
@SpencerPark Cool project. Is there anyway to use your project to communicate to an existing IPython Kernel passing in python code for execution, then access the results?
ie. I can get the connection_file from my IPython Kernel which looks like this.
I too am having success in creating a MyKernel class which extends your BaseKernel but then I am sort of lost in how to execute python code strings. I've tried
eval()
andnew ExecuteRequest()
but not clear on the path forward. On one hand it seems like this project is both a skeleton for 1) creating new Kernels and 2) a messaging app for talking to kernels. I am looking to leverage the messaging pieces, if possible.Another thing I would be interested in knowing is can I use this project to talk to an IPython Kernel Gateway running in a cloud. I think the answer is no. From research it seem like that would entail some web socket communication and I did not see any type of web socket calls in this project.
The text was updated successfully, but these errors were encountered: