Skip to content
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

How to connect to zmqJupyterClient #2

Open
li2109 opened this issue Dec 2, 2021 · 0 comments
Open

How to connect to zmqJupyterClient #2

li2109 opened this issue Dec 2, 2021 · 0 comments

Comments

@li2109
Copy link

li2109 commented Dec 2, 2021

List<String> configPaths =Arrays.asList(
            "/Users/xxx/.jupyter",
            "/Users/xxx/opt/anaconda3/etc/jupyter",
            "/usr/local/etc/jupyter",
            "/etc/jupyter");
    List<String> dataPaths =
        Arrays.asList(
            "/Users/xxx/Library/Jupyter",
            "/Users/xxx/opt/anaconda3/share/jupyter",
            "/usr/local/share/jupyter",
            "/usr/share/jupyter");
    List<String> runtimePaths = Arrays.asList("/Users/xxx/Library/Jupyter/runtime");

    JupyterPaths jupyterPaths =
        new JupyterPaths(
            configPaths.stream().map(Path::of).collect(Collectors.toList()),
            dataPaths.stream().map(Path::of).collect(Collectors.toList()),
            runtimePaths.stream().map(Path::of).collect(Collectors.toList()));

    KernelSpecManager kernelSpecManager = KernelSpecManager.fromPaths(jupyterPaths);

    Map<String, KernelSpec> allSpecs = kernelSpecManager.getAllSpecs();
    System.out.println(allSpecs);
    KernelConnectionProperties kernelConnectionProperties =
        new KernelConnectionProperties(
            "127.0.0.1", 8990, 8991, 8992, 8993, 8994, "tcp", "hmac-sha256", "");

    ZmqJupyterClient zmqJupyterClient =
        ZmqJupyterClient.createConnectedTo(kernelConnectionProperties);

    ExecutionResult eval = zmqJupyterClient.eval("print(1+1)", IOProvider.STDIO);
    String data = (String) eval.getValue().getData(MIMEType.APPLICATION_JSON);
    System.out.println(data);

I confused on the "key" parameter when creating KernelConnectionProperties. which config does this "key" exactly indicate?
is it c.NotebookNotary.secret? c.GatewayClient.client_key? c.NotebookApp.keyfile? c.Session.key?

In addition, how do you tell if a client is connected to the kernel? I run the code above and the console is logging "INFO: Loop started." but nothing from code execution. I really appreciate the code you open sourced. Thank you!

Since there's no doc about the code, do you mind writing a small example code for this zmqJupyterClient?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant