5

I haven't found answers in github or in the jupyter help.

TL;DR: I need a command-line that tells me the same thing as the %connect_info magic, in particular the line Connect with --existing kernel-4e4c970e-cccb-2485-a09d-d56efd10e278.json.

My current setup is to have the jupyter notebook launched from a work server. Then I connect to that server with SSH, and can work in the same kernel by attaching a console to it:

jupyter console --existing kernel-4e4c970e-cccb-2485-a09d-d56efd10e278.json

(in a tmux+vim+slimux setup, which by the way I often find more convenient).

The problem is:

  1. The only way to get the kernel string is from the notebook itself (which may be difficult to access over SSH);
  2. I have several notebook runnings, sometimes I need to quickly check which one I need.

So is there a command to run from the shell on the server, that would list running kernels, which notebook launched them, and ideally if there are consoles attached?

PlasmaBinturong
  • 2,122
  • 20
  • 24
  • Thank you @samcarter_is_at_topanswers.xyz ! I finally found a similar question targeted to the metropolis theme, and `\usebeamercolor[fg]{normal text}` was the key :) – PlasmaBinturong Sep 06 '20 at 13:22

2 Answers2

1

You can list the kernel json files sorted by time with:

ls -tlr ~/.local/share/jupyter/runtime/

-rw------- 1 user user 263  6. Dez 13:40 kernel-c64635b5-6f5c-4938-828b-520d70e2a6c4.json
-rw------T 1 user user 263  7. Dez 11:57 kernel-1bdb41b4-1e87-4672-af92-7c3f3660e19c.json
-rw------T 1 user user 263  7. Dez 16:48 kernel-f7a51511-8c2a-4f0b-9cd3-6e5a79dccab3.json

This will not give you the information about which notebook launched them and if there is a console attached. But the times will give you some hints of which kernel is the one you are looking for, and with some trial and error you will figure it out.

This answer is based on the blog post “Connecting with Ipython from the command line to a running Jupyter session” by DS4N6.

astoeriko
  • 730
  • 8
  • 20
0

A way to list to list running sessions it use the Jupyter REST API in conjunction with the jupyter lab list command (to obtain the token). This provides more information on the paths and files that are running - assuming you're running on localhost:8888:

curl -sSLG localhost:8888/api/sessions --data-urlencode `jupyter lab list | awk '/token/ {split($1,a,"?")} END {print a[2]}'`  | jq
Pierz
  • 7,064
  • 52
  • 59