1

I am using SSH to connect to a linux-base remote server and in that server I have run ipython from the terminal that it has brought to me. The point is that I want to interrupt the current operation but I can not do that at all. I have tried pressing double i or the information that have been provided in this web site but did not work (using Ctrl + m i).

I have seen here and here but were useless.

Green Falcon
  • 818
  • 3
  • 17
  • 48
  • Is `Ctrl+C` not working? – W.Mann Nov 17 '17 at 13:26
  • actually hitting that combination once does not do any thing, but hitting those twice would kill the kernel I guess, I wanted to interrupt it. I have used it twice actually but even that does not work. – Green Falcon Nov 17 '17 at 13:32
  • 1) Please precise if you are using IPython or the Notebook and 2), the link you provide has a big warning at the top that it is out of date (by 3 years) with link to new documentation. – Matt Nov 22 '17 at 23:02
  • @Matt as I have stated I was using ipython in the terminal shell of ubuntu, not the notebook. Although the link maybe is old but I used it a lot whenever dealing with jupyter notebook and was helpful. – Green Falcon Nov 23 '17 at 05:55
  • Ok, thanks. The 2 first document you are pointing to are for the notebook, and `i,i` is also a notebook shortcut. So it make sens it does not work in terminal. I'll write up and answer but if Ctrl-C or Ctrl-\ don't work there is not much you can do. – Matt Nov 23 '17 at 18:31
  • @Matt actually I have used 'i,i' in local ipython and suprisingly it worked but I don't know why it did not work with ssh and remote ipython in terminal. anyway, thanks – Green Falcon Nov 23 '17 at 18:35

1 Answers1

1

There seem to be some confusion in your question – clarified in the comments – as to whether you refer to the Terminal IPython or IPython Notebook. The two are quite different beasts and do not have the same shortcuts/capabilities.

The docs you point to are old, and the up-to-date version for the notebook interface is here, i,i and Ctrl-m,i are shortcut for the Classic Notebook interface (now there is also a JupyterLab interface), when ran in a browser. Almost None of the shortcut of the notebook interface apply to the terminal. The notebook interface is a 2-to-3 process system, you are not asking you computer to kill directly the computation, you are asking the interface to stop it.

When you run IPython at the terminal you are directly executing the CLI-Interface and your code in the same process, so Many shortcut will actually be shortcuts of your terminal IPython have limited control over. Thus the way to interrupt a computation is Ctrl-C (soft terminate) or Ctrl-\ forcibly terminal. (And actually when you press i,i i na notebook, it sends a network request to send Ctrl-C to your computation)

Now if you have a computation done in C (like in NumPy for example) it cannot be easily interrupted. Python will receive a "please stop as soon as you can" but will have the first occasion to do so only when numpy (or your C routine) has finished. The only solution is to kill the process using the kill <pid> command. But this will not only stop your computation but most likely kill the all IPython session itself.

You may also try Ctrl-Z (if your terminal support it) that should pause the process and put it in background. Not sure how that would behave in an SSH session though.

Matt
  • 27,170
  • 6
  • 80
  • 74