Reset ipython kernel

前端 未结 7 1871
情书的邮戳
情书的邮戳 2020-12-16 09:47

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

相关标签:
7条回答
  • 2020-12-16 09:55

    I personaly use add these two lines at the top of each ipynb file in JupyterLab:

    load_ext autoreload
    %autoreload 2
    

    It allows you to update the code in an adjacent xxx.py file, without having to restart the Kernel, which was a huge painpoint for me.

    0 讨论(0)
  • 2020-12-16 09:59

    In 3.7 Anaconda, just go to Kernel, select Restart

    0 讨论(0)
  • 2020-12-16 10:02

    I could restart the kernel, but some console sessions take longer to reconnect. Notebook detects kernel restart instantly.

    ipykernel.ipkernel.IPythonKernel class has a do_shutdown method with restart parameter which defaults to False.

    Get a reference to ipykernel.kernelapp.IPKernelApp which has a reference to the kernel and call do_shutdown of the kernel by passing True.

    import IPython
    app = IPython.Application.instance()
    app.kernel.do_shutdown(True)  
    

    How did I test?

    $ #start notebook
    $ jupyter notebook
    
    $ #connect to existing kernel
    $ jupyter console --existing
    
    0 讨论(0)
  • 2020-12-16 10:04

    In the qt console you could hit ctrl-

    0 讨论(0)
  • 2020-12-16 10:09

    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.

    0 讨论(0)
  • 2020-12-16 10:10

    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.

    0 讨论(0)
提交回复
热议问题