How to interrupt the kernel in Jupyter notebook
Last Updated :
13 May, 2024
In this article, we will cover How to interrupt the kernel in Jupyter Notebook we will discuss various methods to do the same. First, we look at what is Jupyter Notebook followed by various methods to interrupt the kernel in Jupyter Notebook.
Jupyter Notebook
The Jupyter Notebook is the original web application for creating and sharing computational documents that contain live code, equations, visualizations, and narrative text. It offers a simple, streamlined, document-centric experience. Jupyter has support for over 40 different programming languages and Python is one of them.
Kernel
In the context of Jupyter Notebook, the kernel is an engine that executes the code within the notebook, it interprets and runs the code in the notebook and manages the execution environment. There are different kernels available in the Jupyter Notebook like the Python3 kernel to execute the code of Python. Sometimes kernel gets stuck in an infinite loop or the code cell execution doesn't stop and we have to forcefully interrupt the kernel in this article we will cover various methods to interrupt the kernel.
Interrupting the kernel in Jupyter notebook
There are 3 ways to interrupt the kernel in Jupyter Notebook which are as follows:
- Using Keyboard shortcut
- Using Menu options
- Using Toolbar
1. Keyboard Shortcut
To delete a cell using a keyboard shortcut, follow these steps:
- Press "i i" i.e. press "i" twice to interrupt
You can also edit keyboard shortcuts by selecting Menu option Help -> Edit Keyboard Shortcuts then select interrupt kernel and add new shortcut key, refer to below screenshot,

2. Using Menu Options
Follow the below steps to interrupt the kernel using menu options,
- Navigate to Menu Options Kernel -> Interrupt to interrupt the kernel
Refer the below screenshots,

3. Using Toolbar
To interrupt the kernel from the toolbar click on "Square" icon in the toolbar it will interrupt the kernel,

Why Interrupting the Kernel is Necessary
To understand why interrupting the kernel is nescessay let's consider an example in which a code block is running an infinite loop or a recursion without base case in both the scenerios the kernel will executes the code block indefinite time until any memory fault or any other error arises. Hence we will have to interrupt the kernel which will helps in debugging the code and optimize the code to make the program more time efficient, interrupting the kernel will helps to halt the code block that may consume excessive CPU time or memory resources, preventing system slowdown.
What Happens When You Interrupt the Kernel
When the kernel is interrupted first thing that happens is the code execution got stopped and any code cell running in the notebook got forcefully halted by the system and any output generated by that cell upto that point is displayed. When the kernel is interrupted the kernel is still active and user can continue its work in notebook and also the state of the kernel like variable, libararies that are imported etc are preserved, user can continue work in the notebook without loosing its state.
Handling Interrupted Kernels
When the kernel is interrupted there are various ways to handle them like user can continue working on the notebook since the state of the kernel is preseved, or user can choose to shutdown the kernel completely by going to menu options Kernel -> Shutdown or user can restart the kernel and re-run all the cells which clears the state of the kernel and executes all the cells sequentially to get the updated outputs by going to menu options Kernel -> Restart & Run all.
Similar Reads
How to Fix Kernel Error in Jupyter Notebook
Jupyter Notebook is an open-source framework that comes under Anaconda software. It is a free cloud-based interactive platform used for computing in different types of languages. It is used for data analysis, visualizations, numerical calculations and simulations, equations, executing codes, machine
15 min read
How to Install PySpark in Jupyter Notebook
PySpark is a Python library for Apache Spark, a powerful framework for big data processing and analytics. Integrating PySpark with Jupyter Notebook provides an interactive environment for data analysis with Spark. In this article, we will know how to install PySpark in Jupyter Notebook. Setting Up J
2 min read
How to Install Scala in Jupyter IPython Notebook?
It is a very easy and simple process to Install Scala in Jupyter Ipython Notebook. You can follow the below steps to Install it. Before that, let us understand some related terms. The Jupyter Notebook is an open source web application that anyone can use to create documents as well as share the docu
2 min read
How to Install Scala Kernel in Jupyter?
Jupyter notebook is widely used by almost everyone in the data science community. While it's a tool with extensive support for python-based development of machine learning projects, one can also use it for Scala development as well, using the spylon-kernel. In this article, we will see how to instal
1 min read
How to Install ipython-sql package in Jupyter Notebook?
ipython-sql is a %sql magic for python. This is a magic extension that allows you to immediately write SQL queries into code cells and read the results into pandas DataFrames. Using this, we can connect to any database which is supported SQLAlchemy. This is applicable to both classic notebooks and t
2 min read
How to Install Jupyter Notebook on MacOS?
Jupyter Notebook is a popular web-based interactive computing environment, widely used among data scientists and programmers. Working with Jupyter Notebook in MacOS helps perform various tasks including data cleaning and transformation, numerical simulation, statistical modelling, data visualization
5 min read
How to Change the Theme in Jupyter Notebook
In this article, we will cover how to change the theme in Jupyter Notebook. We will look at what is Jupyter notebook, the themes why we use them, and the different themes available in Jupyter Notebook we will look into examples along with the screenshots to get a better understanding. We will also s
3 min read
Interactive Graphs in Jupyter Notebook
When working in a Jupyter Notebook environment, you can produce interactive Matplotlib plots that allow you to explore data and interact with the charts dynamically. In this article, we'll explore how to create such interactive plots using Matplotlib within Jupyter. Before we proceed with the steps,
3 min read
Make 3D interactive Matplotlib plot in Jupyter Notebook
Matplotlib is a data visualization library. It is difficult to analyze/get an insight into the data without visualizing it. And matplotlib is a great library for doing the visual analysis of data in python. Using matplotlib we can plot 1-D, 2-D and even 3-D data. In this article, we are going to lea
3 min read
How to Add a Python 3 Kernel to Jupyter IPython
In this article, we will cover how to install the IPython kernel and integrate it with Jupyter Notebook. We will look at what is Jupyter notebook, followed by a detailed step-by-step tutorial to install IPython kernel and its integration with Jupyter Notebook along with the screenshots to get a bett
2 min read