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
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.
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
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
If you're ok with losing all currently defined variables, then going to Kernel > Restart will stop execution without closing the notebook.
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)
I suggest to restart the kernel. It will be ready to use then .