magma-nvim icon indicating copy to clipboard operation
magma-nvim copied to clipboard

Connect externally to the kenel

Open manu0600 opened this issue 3 years ago • 4 comments

Hello,

First of all i must say your plugin is absolutely amazing !! Thanks for the efforts

Is is possible to connect externally to the kernel of Magma ? After running MagmaInit, I would like to be able to connect to the kernel by opening a second terminal and running jupyter console --existing xxxx (where xxxx is the kernel number), but I don't see any kernel open in ~/.local/share/jupyter/runtime/ so I don't know how to do this

Thank you

manu0600 avatar Sep 13 '22 21:09 manu0600

First of all i must say your plugin is absolutely amazing !! Thanks for the efforts

Thank you!

Is is possible to connect externally to the kernel of Magma ? After running MagmaInit, I would like to be able to connect to the kernel by opening a second terminal and running jupyter console --existing xxxx (where xxxx is the kernel number), but I don't see any kernel open in ~/.local/share/jupyter/runtime/ so I don't know how to do this

Huh, you should be able to do this. Maybe I have to add some flag to when I start the Jupyter kernel?

I'm a bit short on time right now, but as soon as I'm able to I'll look into this.

dccsillag avatar Sep 18 '22 12:09 dccsillag

I found the way to do it, but I don't know how to automate it (implement it to a keyboard shortcut) :

  • After Magma is initialized, run the magic %connect_info, the output should look like :
Out[1]: ✓ Done
{
  "shell_port": 35121,
  "iopub_port": 60779,
  "stdin_port": 56463,
  "control_port": 43703,
  "hb_port": 44525,
  "ip": "127.0.0.1"
  "key": "d5131461-8641bcaa83d89d5ded4e3247"
  "transport": "tcp"
  "signature_scheme": "hmac-sha256"
  "kernel_name": "
}

Paste the above JSON into a file, and connect with:
    $> jupyter <app> --existing <file>
or, if you are local, you can connect with just:
    $> jupyter <app> --existing /tmp/tmp8_1oeodg.json
or even just:
    $> jupyter <app> --existing
if this is the most recent Jupyter kernel you have started.
  • The kernel file is /tmp/tmp8_1oeodg.json

Could you maybe run that command at the end of MagmaInit and extract the location of the kernel file (in this case /tmp/tmp8_1oeodg.json to have it accessible in a variable (let's say kernel_file) ? This way i could either print it, and open it manually, or automate something with a floating terminal like toggleterm.nvim

manu0600 avatar Sep 22 '22 10:09 manu0600

Another way to find the kernel file path is using ps aux, where the output should look something like :

/.../bin/python3 -m ipykernel_launcher -f /tmp/tmp8_1oeodg.json

Since MagmaInit is launching this command, it should be "easy" to put the location of this kernel file in a variable I guess, but I don't know where to look for it in the source code

manu0600 avatar Sep 22 '22 11:09 manu0600

I was toying with this some as I explore Magma.. but something as silly and simple as ls -t /tmp/*.json | head -n1 would give you the newest json and if its run as soon as Magma starts the kernel.. its a pretty good chance its the correct file.. and thats not hard to throw into a lua function.

usmcamp0811 avatar Nov 20 '22 04:11 usmcamp0811