我在 Emacs 中使用 Python,以及 Elpy 和 iPython。我从带有C- c C-的文件运行代码c,但有时我想终止进程(键盘中断)。我使用相同的快捷方式来尝试终止进程(根据这个问题)。
我的目标是尝试区分杀死整个 Python 进程还是仅仅中断内核。使用上面的快捷方式,它有时会做第一个,有时会做第二个。我还没有找到任何线索,如何概括它。
那么,问题来了:如何停止 Python 进程以及如何中断内核?
我只想定义一个函数来向进程发送中断。我anaconda-mode
不使用elpy
,所以我不确定elpy
获取关联的用途是什么process-buffer
,但python-mode
有python-shell-get-process-or-error
。然后,您可以将 key 绑定到以下函数中C-c C-a。python-mode-map
(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))))