Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get jupyter notebook kernel state?

I want to be able to detect from outside a notebook server if the kernel is busy or actively running some cell.

Is there some way for me to print this state as a command line call or have it returned as the response to a http request.

like image 327
Hamzeh Alsalhi Avatar asked Oct 31 '22 16:10

Hamzeh Alsalhi


1 Answers

There is not, this state is not stored anywhere, in part because it changes rapidly, and in part because there shouldn't be many, if any, actions that should be taken differently based on its value. It is only published via messages on the IOPub channel, which you can connect to via zeromq or websocket. If you want to know the busy/idle state of a kernel:

  1. connect to kernel (zmq or websocket)
  2. initial state is busy
  3. send a kernel_info request
  4. monitor status IOPub messages for busy/idle changes

If the kernel is idle, it will handle the kernel_info request promptly and you will get a status:idle message.

like image 99
minrk Avatar answered Jan 04 '23 14:01

minrk