How to stop the running cell if interupt kernel does not work in Jupyter Notebook

后端 未结 6 879
我在风中等你
我在风中等你 2021-02-05 00:53

I\'m using Jupyter Notebook for a while. Often when I tried to stop a cell execution, interrupting kernel did not work. In this case, what else can I do, other than just closing

相关标签:
6条回答
  • 2021-02-05 01:08

    Recently I also faced a similar issue.

    Found out that there is an issue in Python https://github.com/ipython/ipython/issues/3400 and it was there for 6 some years and it has been resolved as of 1st March 2020.

    0 讨论(0)
  • 2021-02-05 01:12

    Currently this is an issue in the github jupyter repository as well, https://github.com/ipython/ipython/issues/3400 there seems to be no exact solution for that except killing the kernel

    0 讨论(0)
  • 2021-02-05 01:19

    If the iPython kernel did not die, you might be able to inject Python code into it that saves important data using pyrasite. You need to install and run pyrasite as root, i.e. with sudo python -m pip install pyrasite or python3 as needed. Then you need to figure out the process id (PID) of the iPython kernel (e.g. via htop or ps aux | grep ipython), say 3873. Then, write a script that saves the state for example to a pickle in a file inject.py, say, it is a Pandas dataframe df in the global scope:

    df.to_pickle("rescued_df.pkl")
    

    Finally, and inject it into the process as follows:

    sudo pyrasite 3873 inject.py
    

    You may need to enable dtrace first like so:

    echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
    
    0 讨论(0)
  • 2021-02-05 01:21

    If you're ok with losing all currently defined variables, then going to Kernel > Restart will stop execution without closing the notebook.

    0 讨论(0)
  • 2021-02-05 01:31

    This worked for me: - Put the laptop to sleep (one of the power options) - Wait 10 s - Wake up computer (with power button)

    Kernel then says reconnecting and its either interrupted or you can press interrupt.

    Probably isn't fool proof but worth a try so you don't waste previous computation time. (I had Windows 10 running a Jupyter Notebook that wouldn't stop running a piece of Selenium code)

    0 讨论(0)
  • 2021-02-05 01:34

    I suggest to restart the kernel. It will be ready to use then .

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