0

I use Python in Emacs, with Elpy and iPython. I run code from a file with C-c C-c, but sometimes I would like to terminate the process (keyboard interrupt). I use the same shortcut to try to terminate the process (as per this question).

My goal would be to try to distinguish between killing the whole Python process or just interrupting the kernel. With the above shortcut, it sometimes does the first and sometimes does the second. I am yet to find any clues, how to generalize it.

So, the question is: How to stop the Python process and how to interrupt the kernel?

1 Answer 1

2

I would just define a function to send an interrupt to the process. I use anaconda-mode not elpy, so I am not sure what elpy uses to get the associated process-buffer, but python-mode has python-shell-get-process-or-error. Then you could bind the key C-c C-a, for example, in the python-mode-map to the following function.

(defun my-interrupt ()
  "Send an interrupt signal to python process"
  (interactive)
  (let ((proc (ignore-errors
                (python-shell-get-process-or-error))))
    (when proc
      (interrupt-process proc))))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.