目前,我正在接受ThreadedKernelClient
:
kernel_manager = KernelManager(client_class='IPython.kernel.threaded.ThreadedKernelClient')
kernel_manager.start_kernel()
kernel_client = kernel_manager.client()
但是,我不确定如何为传入的消息注册回调(在我运行execute
之后)。有人能指出我正确的方向吗?
答案 0 :(得分:0)
我所做的是子类ThreadedZMQSocketChannel
和ThreadedKernelClient
,并覆盖call_handlers
,例如:
class TestChannel(ThreadedZMQSocketChannel):
def call_handlers(self, msg):
# do something
class TestClient(ThreadedKernelClient):
iopub_channel_class = Type(TestChannel)
shell_channel_class = Type(TestChannel)
stdin_channel_class = Type(TestChannel)
您的经理看起来像:
kernel_manager = KernelManager(kernel_name='python', client_class='__main__.TestClient')
start_channels
后,您的call_handlers
方法将使用execute
等方法的结果进行调用。