带嵌入式python的qt应用程序中的jupyter笔记本内核

时间:2018-10-29 14:12:50

标签: jupyter-notebook

我们有一个基于QT的C ++应用程序(myapp.exe),具有嵌入式python init。 如何在我们的应用程序内创建可以与jupyter Notebook交互的内核?

使用以下代码,内核自动死亡。有人可以提出解决方案吗

我们的nalnal.json文件内容为:

{
 "argv": [
  "D:/myapp.exe",
  "-f",
  "{connection_file}",
  "-input",
  "D:/test.py",
 ],
 "display_name": "test",
 "language": "test"
}

我们的内核代码(放置在文件test.py中):

from ipykernel.kernelbase import Kernel

class TEST(Kernel):
    implementation = 'Echo'
    implementation_version = '1.0'
    language = 'no-op'
    language_version = '0.1'
    language_info = {
        'name': 'Any text',
        'mimetype': 'text/plain',
        'file_extension': '.txt',
    }
    banner = "Echo kernel - as useful as a parrot"
    def __init__(self, **kwargs):
        super(Kernel, self).__init__(**kwargs)
    def do_execute(self, code, silent, store_history=True, user_expressions=None, allow_stdin=False):
        if not silent:
            stream_content = {'name': 'stdout', 'text': code}
            self.send_response(self.iopub_socket, 'stream', stream_content)

        return {'status': 'ok',
                # The base class increments the execution count
                'execution_count': self.execution_count,
                'payload': [],
                'user_expressions': {},
               }

if __name__ == '__main__':
    from ipykernel.kernelapp import IPKernelApp
    IPKernelApp.launch_instance(kernel_class=TEST)

0 个答案:

没有答案