[IPython-dev] Front end ''status_started.Kernel" event and websocket status

Stephen Chan sychan at lbl.gov
Tue Aug 20 20:29:00 EDT 2013

    I've been doing some front end work on the notebook and started
using the status_started.Kernel event to push authentication tokens
from the browser to the ipython kernel for use in 'backend' code.

   The browser code initializes before IPython.notebook.kernel is
initialized, so I bound handler to status_started.Kernel to wait for
the kernel to come up before calling IPython.notebook.kernel.execute()
   The problem is that when I call IPython.note.kernel.execute() I am
getting a DOM error that the web socket is not in readyState 1. It
looks like the websocket constuctors in
Kernel.prototype.start_channels() are non-blocking and return before
the shell_channel is ready for a send(). This is happening on the
latest Chrome (haven't tried it on FF or Safari yet).

   I'm kludging around this currently by checking the readyState on
the shell_channel, and if it isn't ready, using setTimeout for 500ms
before calling IPython.notebook.kernel.execute()

   There's an event for websocket closed, but not one for websocket
opening. Would it make sense to either add another event for the
websocket, or else only trigger the status_started.Kernel event once
all the websockets are up? Is there another way to deal with this?


More information about the IPython-dev mailing list