StackG StackG - 9 months ago 33
Python Question

iPython Notebook in Firefox - Warning: unresponsive script

I had a long script running on iPython notebook in Firefox for a long time. I came back and it seemed to have hung up, so I saved it and closed it.

When I re-open the script, I get a dialog box pop up with the following error:

Warning: unresponsive script

A script on this page may be busy, or it stack overflow may have
stopped responding. You can stop the script now, open the script in
the debugger, or let the script continue.

The options are 'continue', 'stop script' and 'debug script'. Clicking on any of these leads to the same result, the dialog box disappears and the iPython notebook is unresponsive (for example, ctrl+enter creates a line-break in the current cell rather than executing it).

Worst of all however, the cells at the bottom of the script seem to have been cut off. They contained some valuable code which seems to have gone, this is quite a bad outcome!

I've tried rolling back but the last roll-back point also shows the bottom cut off. Any support here much appreciated!


I have now worked this out and leave it here in the hope it will help others.

The cause of the problem seemed to be an excessively long output from one of the cells - everything below this line had been cut off in the iPython browser, but I discovered it still exists in the .ipynb file and all I had to do was remove some of the output lines, and when I re-opened the file it ran without problems AND my code that had been cut off was available once again.

The notebooks store everything in JSON format. In my case, I needed to remove output from one of the cells, which I did like this:

  1. Browse to your iPython Notebooks directory (NOT where ipython.exe resides) - for me they were in C:\Users\myname\Documents\IPython Notebooks
  2. Right-click on the offending notebook.ipynb file, and edit in a text editor - my choice is Notepad++
  3. Scroll down to the cell which has generated lots of output lines. Each of these lines is inside the cell's outputs property, with "output_type": "stream"
  4. Remove an arbitrary number of these output entries, but be sure to remove anything outside the output property itself, and be sure to remove from the back of a tailing comma to the front of the following comma so that the resulting JSON is well-formed

A typical line of output looks like this, deleting several hundred of them made my script run again in the browser:

   "output_type": "stream",
   "stream": "stdout",
   "text": [
    "Added 150000 records so far"