[Solved] Jupyter Notebook not running code Stuck on In [*]

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
3 min

banner

# [Solved] Jupyter Notebook not running code Stuck on In [*]

The issue where Jupyter Notebook doesn't run your code and is stuck on "In [*]" means that Jupyter is still running your code within the kernel.

To resolve the issue, make sure:

  • You don't have an infinite loop in your code or a function that recursively invokes itself.

  • You aren't trying to connect to a database that is currently offline.

jupyter notebook not running code stuck on in asterisk

# Make sure the problem is not within your code

Make sure that the problem is not within your code.

The issue most often occurs:

  • if you have an infinite loop
  • if you have a function that recursively invokes itself infinitely
  • if you are trying to connect to a database that is offline, so the attempt times out
  • if you are making an HTTP request to a server that doesn't respond without timeout set up

If the issue is within your code, you have to resolve it as interrupting the kernel and rerunning your code wouldn't help.

# Interrupt and restart the Kernel

The first thing you should try is to click on the square "Interrupt the kernel button".

click interrupt the kernel button

Here is a short clip that demonstrates how this works.

click interrupt kernel button

If the issue persists:

  1. Click on the Kernel button in the top menu.
  2. Click on Interrupt.
  3. Click on the Kernel button again.
  4. Select Restart.

kernel interrupt and restart

  1. When you get prompted, whether you want to restart the Kernel, click on Restart.

Here is a short clip that shows how this works.

kernel interrupt and restart

Another thing you can try is to:

  1. Click on Kernel in the top menu.
  2. Click on Restart & Run all.

kernel restart and run all

You can also try to:

  1. Click on Kernel in the top menu.
  2. Click on Shutdown.
  3. Click on Kernel again.
  4. Select Restart.

If that didn't help either, stop your jupyter-notebook server and restart it.

  1. Save any changes you've made.
  2. Focus your terminal window, press Ctrl + C (or Cmd + C on macOS), type y and hit Enter.

stop jupyter notebook server

  1. Type jupyter-notebook to start your server again.

# Upgrade IPykernel if the issue persists

If the issue persists, try to upgrade the ipykernel package.

Run the following command from your terminal.

shell
pip install --upgrade ipykernel # Or with pip3 pip3 install --upgrade ipykernel

upgrade ipykernel

You can try to restart the Kernel if the issue persists.

If you use Anaconda, try issuing the following command.

shell
conda update ipykernel # Or conda install ipykernel

You can also try to update the Anaconda meta package if you use Anaconda.

shell
conda update conda conda update anaconda

If the issue persists:

  1. Click on the Kernel button in the top menu.
  2. Click on Interrupt.
  3. Click on the Kernel button again.
  4. Select Restart.

kernel interrupt and restart

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.