i trying run groovy kernel sub-kernel in python. have added custom cell magic in python, when user types %%groovy
groovy kernel should started using jupyter_client manager , execute code. currently, having problem sending response. appreciated. here code far:
from ipython.core.magic import (magics, magics_class,cell_magic) jupyter_client import manager ipykernel.kernelbase import kernel @magics_class class groovykernelmagic(magics,kernel): _execution_count = 1 def run_cell(self, code): if not self.kernelmanager.is_alive(): kernel.send_response(kernel.iopub_socket, 'stream', {'name': 'stdout', 'text': 'restarting kernel "{}"\n'.format(self.kernelmanager)}) self.kernelmanager.restart_kernel(now=false) self.kernelclient = self.kernelmanager.client() while self.kernelclient.shell_channel.msg_ready(): self.kernelclient.shell_channel.get_msg() self.kernelclient.execute(code, silent=false) _execution_state = "busy" while _execution_state != 'idle': while self.kernelclient.iopub_channel.msg_ready(): sub_msg = self.kernelclient.iopub_channel.get_msg() msg_type = sub_msg['header']['msg_type'] if msg_type == 'status': _execution_state = sub_msg["content"]["execution_state"] else: if msg_type in ('execute_input', 'execute_result'): sub_msg['content']['execution_count'] = self._execution_count kernel.send_response(kernel.iopub_socket, msg_type, sub_msg['content']) reply = self.kernelclient.get_shell_msg(timeout=10) reply['content']['execution_count'] = self._execution_count return reply['content'] @cell_magic def groovy(self, line, cell): self.kernelmanager, self.kernelclient = manager.start_new_kernel(startup_timeout=60, kernel_name='groovy') return self.run_cell(cell) ip = get_ipython() ip.register_magics(groovykernelmagic)
this error stack trace:
/testmagic.py in groovy(self, line, cell) 50 def groovy(self, line, cell): 51 self.km, self.kc = manager.start_new_kernel(startup_timeout=60, kernel_name='groovy') ---> 52 return self.run_cell(cell) 53 54
/testmagic.py in run_cell(self, code) 42 print(msg_type) 43 print(sub_msg['content']) ---> 44 kernel.send_response(kernel.iopub_socket, msg_type, sub_msg['content']) 45 reply = self.kc.get_shell_msg(timeout=10) 46 reply['content']['execution_count'] = self._execution_count
anaconda3/lib/python3.5/site-packages/ipykernel/kernelbase.py in send_response(self, stream, msg_or_type, content, ident, buffers, track, header, metadata) 343 message. 344 """ --> 345 return self.session.send(stream, msg_or_type, content, self._parent_header, 346 ident, buffers, track, header, metadata) 347
attributeerror: 'any' object has no attribute 'session'
Comments
Post a Comment