Ipython: Cannot interrupt infinite loops in the notebook

Created on 13 Jan 2013  ·  29Comments  ·  Source: ipython/ipython

I recently gave an introduction to Python programming at the Workshop on Genomics. For the tutorial, we used the notebook interface and it was very well received (thank you!). During the discussion on loops, I asked the students to convert an example for loop into a while loop. In the process many of the students created infinite loops. For some of those students, it crashed Firefox. The fix was to kill the notebook server and kill the browser. All of the students were using Ubuntu-based virtual machines and Firefox as the browser. If it would help, I can get further details about the systems as well as investigate if I can recreate this behavior on my copy of the virtual machine.

needs-info

Most helpful comment

I think one of us needs to find a simple notebook that replicates this issue, at least on some system.

while True:
    print "foo"

This makes Firefox use 100% CPU and unresponsive in any way or form. Killing Firefox and the IPython process is the only way to get the system back.

Ipython 3.0.0
Firefox 42.0
Linux 3.13.0-24-generic

All 29 comments

Would by any chance the crashing one producing output and not the one that did not crash the browser?
( you should have a kill kernel in one menu)

We could probably have a security opt-in timeout that kills the server si kernel stay busy too long, or of frontend receive too much input

I think there are two issues here:

  • Interrupting an infinite loop is perfectly possible. On the Kernel menu, click interrupt.
  • If your loop prints something at each step, it will produce a huge amount of output, which might cause problems for the browser. See also issue #1975.

@Carreau there was no output

@takluyver the kernel menu was not responsive. This would happen with loops that were printing and loops that were not printing.

Can you give an example of a loop where it doesn't work?

On 13 January 2013 16:11, Daniel McDonald [email protected] wrote:

@Carreau https://github.com/Carreau there was no output

@takluyver https://github.com/takluyver the kernel menu was not
responsive. This would happen with loops that were printing and loops that
were not printing.


Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/issues/2781#issuecomment-12195606.

A naive/horrible anagram algorithm when the words are not anagrams of each other

from random import shuffle 
word1 = list("quietx")
word2 = list("quite")
while word1 != word2:
    shuffle(word1)

I've just tested, and I can interrupt that one with no problems on Firefox & Ubuntu. Can you reliably replicate it on your system?

I cannot replicate it on my system. I'll track down users who had the issue and rerun on their systems. The workshop sessions resume tomorrow morning -- workshop is in Europe and today is a day off -- so it'll be a little bit before I can get back on this.

I'm no longer in a position to test this and was unable to follow up at the
workshop. Given that I cannot reproduce the issue, nor can anyone else,
lets chalk it up to a fluke.

Thanks again for the rapid response and I apologize for eating time on this

On Sun, Jan 13, 2013 at 9:57 AM, Thomas Kluyver [email protected]:

I've just tested, and I can interrupt that one with no problems on Firefox
& Ubuntu. Can you reliably replicate it on your system?


Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/issues/2781#issuecomment-12196271.

No worries. Feel free to reopen if you find a way to reproduce the bug.

I get this all the time in IPython notebook in chrome (and I just tested it in firefox, and it "succeeded", i.e. it crashed). I _think_ it happens any time I have an infinite loop that prints frequently. It's an issue for me, because I'm often putting in print statements to debug, and in this, I lose the code that was supposed to fix my bug because of a crash.

Her'es the code I used to make it crash:

import numpy as np
x = np.array([0,1,2,3,4])
it = np.nditer(x,flags=['f_index'])
while not it.finished:
print it.index

This happens with me too...
First the browser becomes non-responsive and later I find the whole system hang. I am forced to do a hard-reset.
I use Ubuntu with xfce desktop / firefox.
If it would be helpful I would be willing to share any other details that you might require to fix this ...
@minrk

This issue seems still there!

I can run the "interrupt" or "Restart" from kernel menu but it didn't take effect at all. the running icon still displayed as a black ball.

Even if I restart computer, after I click the notebook again, it's will loop there forever!

I am using MacBook with ipython 2.2.0 installed.

I have also had this issue: ipython notebook hanging in the browser, and unable to recover using interrupt kernel. In addition to loop errors, this seems to happen with any hanging process, e.g. if an internet query within a function hangs for network reasons.

My question is, is there a way to access the underlying kernel from the command line? I launch ipython notebook from a terminal, and at the moment my solution is to keyboard interrupt that terminal, which shuts down the kernel entirely.

I also have this critical issue. It seems to be related to loops indeed. This prevents me from running long simulations or data analysis, which means: I'm screwed...

I don't know if it's related but I noticed that once it hangs, the hyperthreading seems to collapse into one CPU still working. You can see that by using htop, for example. At first, it seemed to me that hyperthreading (which the numpy -> BLAS libraries are exploiting on my machine) was the one crashing and then the whole thing would run crazy slow, but then I tried to interrupt and had no luck and so I realized it was the IPython kernel just getting stuck.

This problem never occured me when:

  • I was using an older machine (but still very similar, just fewer RAM and CPUs)
  • I was using old ipython<3.0
  • I was not working on a remote IPython notebook

My educated guesses are:

  • issue with the some socket somewhere...
  • matplotlib threading backends are messing up <-- but that's just because they almost always do so better put there the bet ;)

When the problem occurs, I just restart the kernel from within the web interface and re-do what I was doing...

EDIT: it is hard for me as well to reproduce it but I noticed that if I don't use BLAS, for example if I don't use numpy's dot product, the problem doesn't appear, although I should run some more tests to verify that.

I also see this problem quite frequently and it's hard to resolve - if there is a lot of data that is time-consuming to process in the kernel, it can be quite a pain to kill everything and force a restart. Definitely not an imaginary bug :)

I also have this problem on OSX + chrome.

@minrk, I think this may be worth reopening. I don't have sufficient privs to just reopen short of creating a new issue.

From the CLI it looks like pressing the stop button is doing something, but the notebook remains completely unresponsive.

[I 15:26:22.224 NotebookApp] Kernel interrupted: edee0497-b340-43fd-be77-1ad67e5170ee
[I 15:26:32.197 NotebookApp] Kernel interrupted: edee0497-b340-43fd-be77-1ad67e5170ee
[I 15:26:42.688 NotebookApp] Saving file at /Untitled.ipynb
[I 15:27:30.993 NotebookApp] Kernel interrupted: edee0497-b340-43fd-be77-1ad67e5170ee
[I 15:27:35.605 NotebookApp] Kernel interrupted: edee0497-b340-43fd-be77-1ad67e5170ee
[I 15:28:43.999 NotebookApp] Saving file at /Untitled.ipynb
[I 15:29:28.038 NotebookApp] Kernel interrupted: edee0497-b340-43fd-be77-1ad67e5170ee

I think one of us needs to find a simple notebook that replicates this issue, at least on some system. Otherwise it will probably not be fixable.

I'm also seeing this problem.

I think one of us needs to find a simple notebook that replicates this issue, at least on some system.

while True:
    print "foo"

This makes Firefox use 100% CPU and unresponsive in any way or form. Killing Firefox and the IPython process is the only way to get the system back.

Ipython 3.0.0
Firefox 42.0
Linux 3.13.0-24-generic

I can reproduce with
ipython 3.2.0
python 2.7.10
Chrome Version 46.0.2490.86 (64-bit)
OSX 10.10.5

Pretty huge annoyance for me, too. I often have to kill the entire notebook server along with chrome because of this problem. I can get to the point where I click the interrupt kernel button and it highlights as if it was clicked, but something, somewhere doesn't receive the message to stop.

My initial impression is that it's a problem with chrome's text rendering engine, but I know little on how that works.

Another example of slowness is when a relatively large matplotlib comes to the foreground after scrolling to it. The entire notebook becomes extremely jittery for a good 4-5 seconds.

For what it's worth, I'm using a fairly beefy machine, so it's especially weird that jupyter can bring my entire machine to its knees.

9/10, it happens on accident, so it's not as easy as calling it a user error bug.

I just had this problem occur for me (or at least it fits the profile described above). I couldn't get window to be regularly responsive, but _I could_ do a very slow clipboard copy of the whole page, which allowed me to retain my recent code changes.

Not a solution to the problem, but a potential way to mitigate its consequences.

I've had the same problem today and in the past, running Linux Mint(18.0) and firefox. It was a very simple count() generator, but I was messing with __getitem__ and, in a silly way, set a print on the key.

The latest versions of our packages implement output throttling, which should mitigate the issues with large amounts of output slowing the browser down.

Closing as this issue is not in IPython itself and if still problematic and relevant should be opened on the right repository. This will allow to keep the number of opened issue on the IPython repo under control.

Feel free to keep commenting or reopen if necessary.

Thanks.

@Carreau, do you have a suggested repository (or did this just not get carried over to where the notebook issues are tracked...)?

That will need to be migrated either to jupyter/notebook or jupyterlab/jupyterlab. LIkely second one if it affects jupyterlab as well.

Was this page helpful?
0 / 5 - 0 ratings