Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart ipython Kernel with a command from a cell

Is it possible to restart an ipython Kernel NOT by selecting Kernel > Restart from the notebook GUI, but from executing a command in a notebook cell?

like image 258
pebox11 Avatar asked Jun 10 '16 14:06

pebox11


People also ask

How do I restart IPython kernel?

You can run the whole notebook in a single step by clicking on the menu Cell -> Run All. To restart the kernel (i.e. the computational engine), click on the menu Kernel -> Restart.

How do I run IPython notebook from command line?

Be sure to activate the environment in the terminal using the command conda activate earth-analytics-python before running the jupyter notebook command. When you type this command into the terminal, it will launch a local web server on your computer. This server runs the Jupyter Notebook interface.

How do you restart a cell in Jupyter notebook?

You can restart your Jupyter Kernel by simply clicking Kernel > Restart from the Jupyter menu. Note: This will reset your notebook and remove all variables or methods you've defined! Sometimes you'll notice that your notebook is still hanging after you've restart the kernel.


2 Answers

As Thomas K. suggested, here is the way to restart the ipython kernel from your keyboard:

import os os._exit(00) 
like image 177
pebox11 Avatar answered Oct 03 '22 21:10

pebox11


import IPython  IPython.Application.instance().kernel.do_shutdown(True) #automatically restarts kernel 
like image 21
user1348692 Avatar answered Oct 03 '22 23:10

user1348692