jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.57k stars 4.85k forks source link

List currently active kernels in jupyter session #5013

Open naefl opened 4 years ago

naefl commented 4 years ago

I've Google'd quite a bit to find a solution for the following use-case.

Essentially, my root problem is that I try to find a way to automatically persist an interactive ipython session such that I can restore its state in case a) any client gets disconnected or the jupyter server is stopped, or b) to connect from a different front-end in a different client (might be from completely different device connecting through ssh/mosh, like my iPhone/iPad).

I have also looked into alternatives, such as dill, however they require manual saving of the state. Hence, I think having a running ipython kernel on my remote cloud machine is the way to go. So, then, I would need a way to connect multiple front-ends to the same ipython kernel.

These front-ends might be:

I currently keep a Jupyter server running on my cloud machine, I then connect to the machine using VSCode interactive python (using their new built in way of connecting to Jupyter), which will automatically start a new kernel (I cannot seem to connect to an existing one so this front-end appears to have to be the first to connect).

Jupyter will then log the new kernel id to the terminal, which I can then append to

jupyter console/notebook --existing kernel-<ID read from terminal output or from %connect_info>.json

There is multiple issues here, however.

1) VSCode will disconnect as soon as connectivity is lost and cannot reconnect to the kernel, hence, in 99% of the cases I cannot use %connect_info 2) Jupyter notebook logs a lot of info to the terminal, scrolling up in tmux after having the server running for more than 2mins becomes an ordeal

So my questions:

a) Is there a smarter, built-in way to solve my root problem? b) If not, how do I get a list of running active kernels from a jupyter server so I can connect to them?

Thanks a lot!

jasongrout commented 4 years ago

Can you query the rest api? That's how clients are able to list the current kernels.

Most clients will launch sessions (not just raw kernels). To see sessions, do something like the equivalent of

curl -sSLG localhost:8888/api/sessions --data-urlencode 'token=c9d0073a720e7062a6a702f8cf52075be0383c8d95211984'

(or use python requests, etc.)