I was wondering if there is a way to restart the ipython kernel without closing it, like the kernel restart function that exists in the notebook. I tried %reset
but that doesn't seem to clear the imports.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
I could restart the kernel, but some console sessions take longer to reconnect. Notebook detects kernel restart instantly.
ipykernel.ipkernel.IPythonKernel
class has ado_shutdown
method withrestart
parameter which defaults toFalse
.Get a reference to
ipykernel.kernelapp.IPKernelApp
which has a reference to the kernel and calldo_shutdown
of the kernel by passingTrue
.How did I test?
In the qt console you could hit
ctrl-
Even though it would be handy if
%reset
would clear the namespace and the cache for the imports (as in the notebook) one can explicitly reload a previously imported module usingimportlib.reload
in python3.4 orimp.reload
in python3.0-3.3 (and if needed reset the kernel in a second step).IPython Qt-console has a reset kernel feature. You could use that if you are using IPython Qt. IMO it is better than using from the shell.
If you have installed Spyder with anaconda, then open Spyder window.
Then Consoles (menu bar) -> Restart Consoles.
or you can use CTRL+. which is a shortcut key to restart the console.
From https://github.com/jupyter/notebook/blob/f19d68a33193dff07e62f11da0ebce331e8acbda/notebook/services/kernels/handlers.py#L75: