Python 通过jupyter_客户端API优雅地中断jupyter内核
我的目标是使用Python 通过jupyter_客户端API优雅地中断jupyter内核,python,ipython,jupyter,jupyter-console,Python,Ipython,Jupyter,Jupyter Console,我的目标是使用jupyter_客户端API连接到正在运行的jupyter qtconsole,并在该内核上远程执行命令。代码的执行工作正常,但似乎无法使用Ctrl-C(在qtconsole或console中)从内核前端中断正在运行的代码。下面是我在qtconsole的不同实例中执行的示例代码,该实例不能被中断: import jupyter_client as jc # Find last accessed connection file cfile = jc.find_connection_
jupyter_客户端
API连接到正在运行的jupyter qtconsole
,并在该内核上远程执行命令。代码的执行工作正常,但似乎无法使用Ctrl-C
(在qtconsole
或console
中)从内核前端中断正在运行的代码。下面是我在qtconsole
的不同实例中执行的示例代码,该实例不能被中断:
import jupyter_client as jc
# Find last accessed connection file
cfile = jc.find_connection_file()
km = jc.KernelManager()
km.load_connection_file(connection_file=cfile)
kc.start_channels()
msg = """
import time
for k in range(10):
print(k)
time.sleep(1)
"""
kc.execute(msg)
我发现中断执行的唯一方法是直接发送SIGINIT
,例如在另一个jupyter
实例中运行以下命令:
import os
import signal
# pid is process identifier of jupyter kernel that runs the loop
os.kill(pid, signal.SIGINT)
问题:使用jupyter_客户端
API(例如KernelClient
或KernelManager
)中断正在运行的内核是否有更优雅的方法
PS:github上也有一个开放的网站提到了这个问题,但是jupyter开发人员到目前为止还没有很好的响应