How to stop the running cell if interupt kernel does not work in Jupyter Notebook
I have been using Jupyter Notebook for a while. Often when I try to stop a cell execution, interrupting the kernel does not work. In this case, what else can I do, other than just closing the notebook and relaunching it again? I guess this might be a common situation for many people.
Solution 1:
Currently this is an issue in the github jupyter repository as well, https://github.com/ipython/ipython/issues/3400 there seems to be no exact solution for that except killing the kernel
Solution 2:
If you're ok with losing all currently defined variables, then going to Kernel > Restart will stop execution without closing the notebook.
Solution 3:
Recently I also faced a similar issue.
Found out that there is an issue in Python https://github.com/ipython/ipython/issues/3400 and it was there for 6 some years and it has been resolved as of 1st March 2020.
Solution 4:
One thing that might work is hitting interrupt a bunch of times. It's possible that a library you are using catches the interrupt signal and only stops after receiving the signal multiple times.
For example, when using sklearn's cross_val_score() I found that I have to interrupt once for each cross validation fold.
Solution 5:
There are a few options here:
-
Change the folder name of data: Works if the cell is running already and pulling data from a particular folder. For example I had a for loop that when interrupted just moved to the next item in list it was processing.
-
Change the code in the cell to generate an error: Works if the cell has not been run yet but is just in queue.
-
Restart Kernel: If all else fails