Kernel Busy to No Connection (Jupyter Notebook)

Thanks Alex for the search.

Both the issues posted on Github seems to be stemming from a different issue and didn’t work for me (I’ve tried the solutions given,) however, I have also posted this issue on Github’s Jupyter section, let me see if someone gets back.

In the meantime, I deleted my instance on EC2 and tried everything all over again
(based on the video Jeremy posted). Quite ‘surprisingly’, it did not work too.

Have you tried temporarily shutting down all virus checkers and firewall software, including whatever is built into your OS? Is this on a laptop? Have you tried going to an internet cafe and connecting to the wifi there? Seems like something on your computer or network is blocking web sockets.

The alternative would be to run ipython (not the notebook) in the terminal. You can then view the notebooks directly on github, and copy and paste commands into your terminal. It’s not ideal, but it would do the job. Here’s how to use the terminal version: http://www.pythonforbeginners.com/basics/ipython-a-short-introduction

Not sure if this error I am getting related or not but at the line of downloading models from vgg I am getting following error on conda prompt.
HTTPServerRequest(protocol=‘http’, host=‘localhost:8888’, method=‘GET’, uri=’/api/kernels/3a89cdae-dd90-488a-bfaa-d1a0d906b6f9/channels?session_id=268F6A8A991C48608D354B4ACBE95C00’, version=‘HTTP/1.1’, remote_ip=’::1’, headers={‘Origin’: ‘http://localhost:8888’, ‘Upgrade’: ‘websocket’, ‘Accept-Language’: ‘en-US,en;q=0.8’, ‘Accept-Encoding’: ‘gzip, deflate, sdch, br’, ‘Sec-Websocket-Version’: ‘13’, ‘Host’: ‘localhost:8888’, ‘Sec-Websocket-Key’: ‘x6UrpBLdjaVzaenzu36qSw==’, ‘User-Agent’: ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36’, ‘Connection’: ‘Upgrade’, ‘Cookie’: ‘username-localhost-8888=“2|1:0|10:1481996091|23:username-localhost-8888|44:YzUwNThlZGY5Y2ZmNDE1OWI3NjY1MjMxOGQyMWM0NTU=|a9f613e893bbb4ddc9aec4ffd886ca065e72700609c25edbfbd4e63fdf409a76”; username-localhost-8889=“2|1:0|10:1482105448|23:username-localhost-8889|44:MDVlNzRkZWUyMDA1NGU3MmFhY2JhOTgyYjI5ZTY2NWI=|4af4db6a6123a40ac4ac58bab78621ec375db0e71d1badd27661202cc1dff8ce”’, ‘Pragma’: ‘no-cache’, ‘Cache-Control’: ‘no-cache’, ‘Sec-Websocket-Extensions’: ‘permessage-deflate; client_max_window_bits’})
Traceback (most recent call last):
File “/Users/trinakarmakar/anaconda2/lib/python2.7/site-packages/tornado/web.py”, line 1425, in _stack_context_handle_exception
raise_exc_info((type, value, traceback))
File “/Users/trinakarmakar/anaconda2/lib/python2.7/site-packages/tornado/stack_context.py”, line 314, in wrapped
ret = fn(*args, **kwargs)
File “/Users/trinakarmakar/anaconda2/lib/python2.7/site-packages/zmq/eventloop/zmqstream.py”, line 191, in
self.on_recv(lambda msg: callback(self, msg), copy=copy)
File “/Users/trinakarmakar/anaconda2/lib/python2.7/site-packages/notebook/services/kernels/handlers.py”, line 373, in _on_zmq_reply
super(ZMQChannelsHandler, self)._on_zmq_reply(stream, msg)
File “/Users/trinakarmakar/anaconda2/lib/python2.7/site-packages/notebook/base/zmqhandlers.py”, line 258, in _on_zmq_reply
self.write_message(msg, binary=isinstance(msg, bytes))
File “/Users/trinakarmakar/anaconda2/lib/python2.7/site-packages/tornado/websocket.py”, line 210, in write_message
raise WebSocketClosedError()
WebSocketClosedError

Hi Jeremy,

At the moment, I’m experimenting this within my home connection and yes, I tried running the
Notebook with Anti-virus disabled - with the same kernel busy status.

However, I’m at a loss with this logic - When I attempt to run Jupyter through Anaconda prompt, it works
without any problems. But, trying to run it with Cygwin results in a Kernel busy status. How could this be the case ?

Isn’t the web-socket supposed to be blocked even with Anaconda Prompt ? Why am I able to run the codes ?
Should I install or enable something extra on Cygwin64 ?

I have faced similar issue, Kernel Busy/dying, before BUT it was for a different notebook and I was running the notebook locally from my Ubuntu workstation.

It was an extension problem for me and I had to install nbserver_extensions config key to resolve it.
Please check your browser logs —

  1. right click on notebook code section
  2. click on inspect element
  3. Check on the console, for errors.

Following posts, https://github.com/ipython-contrib/jupyter_contrib_nbextensions/pull/581 , https://github.com/jupyter/notebook/issues/1414 for more details on nbserver_extension.

I remember this problem since it took some good amount of time to figure out.

Thanks Saurav for your help. I have attached below console outputs for when it works, and when it doesn’t.

This was done on the same machine, same environment - the only difference here being
(Anaconda Prompt & Cygwin64)

Running Jupyter Notebook from Anaconda Prompt - works without any issues (Console output follows)

Running Jupyter Notebook from Cygwin64 - kernel busy status (Console output follows)

I have tried searching the errors and corresponding solutions for the second console (Cygwin error) but none too helpful so far.

Ok, so after 2 weeks of battle, I’ve been able to resolve the Kernel busy problem
that some of you may have experienced.

I want to first thank @jeremy and @lexsys for helping me out here.

This solution is recommended if anyone is experiencing the Kernel busy issue on their Jupyter Notebook
or if your connection goes from Kernel busy to a complete disconnect, or if it recurs again and again.

As shown on Jeremy’s very first Youtube video (AWS Deep Learning Setup), where an AWS instance environment is setup, you would have noticed that there were 3 important steps taken each time you want to connect your machine to an AWS instance.

USUAL STEPS as documented by Jeremy (this is great if all goes well)

  1. Using Cygwin, entering the long SSH command that was generated while configuring AWS; which looks
    like this -

ssh -i /home/Dinesh/.ssh/aws-key.pem ubuntu@ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com

  1. After a successful connection to the server, you would of course type “Jupyter Notebook” -
    without the quotes, to launch the notebook via Cygwin

  2. Finally, you would enter the instance URL on a web browser to access the Notebook GUI -
    ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com

However, there’a small modification required if you’re a little unlucky with a Kernel Dying syndrome (that I had)…
Keeping long story short, the Websocket ping timeout (as seen on the console output above) was
the problem and one method to take is to bypass the proxy with an SSH tunnel.

NEW STEPS

  1. ​Using Cygwin Terminal, enter the command shown below (without the quotes and please modify
    the “aws-key.pem” path in accordance to your own AWS hostname address that was generated while
    creating the AWS instance)

“ssh -L 9999:127.0.0.1:8888 -i /home/Dinesh/.ssh/aws-key.pem ubuntu@ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com

What this command does is; it forwards 127.0.0.1:9999 from the machine to 127.0.0.1:8888 on
AWS Instance-hostname. Important thing to note is the arrangement of the command syntax (such as " -i ").
Please follow this format exactly as switching it fails the command.

  1. Once Cygwin accesses the AWS instance, launch the address http://localhost:9999
    (or 127.0.0.1 instead of localhost) from your favorite web browser.

That should be all.

Happy Deep Learning!

9 Likes

That’s a great idea - nice one!

Nice to hear you have managed to solve the problem and shared solution with others!

Thank you and it’s a pleasure!

Thank you very much, Dinesh. I had the same issue and your solution worked for me.

That’s awesome. Most welcome.

@dinesh Thanks a million for this - you’re a lifesaver! My Jupyter Notebook kernels kept being disconnected forcing me to restart the whole fit() process. Your solution sorted it out.

Thank you for this information. However, in my case, port 9999 won’t work for me so I used a 5-digit port like 32243. Is this safe?

Hi @emiliogozo,

From my own experience using a different port number would not be an issue. I checked that the port-32243
isn’t assigned to anything by IANA - Should be good.

Best,
Dinesh

hi @rauten,

My pleasure, glad it worked for you.

Dinesh

Thanks a lot. I had the same issue and you just saved me two weeks of time to figure out the trick!!

I had a similar problem, and the SSH tunnel did not fix it for me. Reporting this in case it can be of help to others. In my case, I’ve built the environment starting from a standard Ubuntu 16.04 AMI on t2.micro, and I’ve tried both with and without Anaconda (much easier WITH). The end result is the same, kernels unreachable, cells stuck with “*”, websockets not going anywhere, “About” menu saying “Current Kernel Information: Waiting for kernel to be available…”.

For me the answer was simply, use https. I’ve not read anywhere that http can’t be used, but it just didn’t work for me (Jupyter notebook 5.0.0, Python 2.7.13, Anaconda 4.4.0, IPython 5.3.0, and Chrome 59.0.3071.115 on Windows 10 on the client side). I thought I was going to save time by avoiding creating a self-signed cert, and boy I was wrong…

So if you’re like me, don’t even bother trying http and use https instead (the difference is a cert and two lines of jupyter notebook config). The SSH tunnel is useful in its own right anyway (you don’t have to open extra ports on the security groups, and the out-of-box config of jupyter notebook works with localhost).

UPDATE: http://wiki.fast.ai/index.php/Jupyter_notebook describes a different solution (change port to 8889), but that didn’t work either for my environment (with a switch back to http). Only https works for me, with the default port 8888 too.

1 Like

@marcodb, Thanks much. I too had the exact same problem, ssh tunnelling didn’t help, but your https solution did. Thank you for posting your solution!