4

My aim is to connect to a running jupyter qtconsole using the jupyter_client API and to execute commands on that kernel remotely. Execution of code works but it seems not possible to interrupt running code from the kernel frontend using Ctrl-C (either in qtconsole or console). Below my sample code with I execute in a different instance of qtconsole and that can't be interrupted:

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)


The only way I found to interrupt the execution is to send a SIGINIT directly, for example by running the following in another jupyter instance:

import os
import signal

# pid is process identifier of jupyter kernel that runs the loop
os.kill(pid, signal.SIGINT)

Question: Is there a more elegant way of interrupting a running kernel using the jupyter_client API (e.g. KernelClient or KernelManager)?

PS: There is also an open issue on github mentioning this problem but the jupyter developers haven't been very responsive so far.

0 Answers0