Get the latest tech news

Deno-Python – A Debugging Story


07/17/24 11/1/1446 For some reason I wanted to "port" Jupyter Echo Kernel to Deno using deno-python. It shouldn't be too hard I already have relatively complex projects using it: Stimulator Share Here is the python kernel from ipykernel.kernelbase import Kernel class EchoKernel(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 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=EchoKernel) Here is a start at porting (file is called a.ts) #!/usr/bin/env -S deno run --allow-all --unstable-ffi import { NamedArgument, PyObject, python } from "jsr:@denosaurs/python"; const m = python.runModule(` from ipykernel.kernelbase import Kernel class EchoKernel(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" `); // NOTE: this also modifies m.EchoKernel const kernel = PyObject.from(m.EchoKernel); kernel.setAttr( "do_execute", python.callback(() => { //TODO: implement this return { status: "ok", execution_count: 0, payload: [], user_expressions: {}, }; }), ); if (import.meta.main) { const IPKernelApp = python.import("ipykernel.kernelapp").IPKernelApp; IPKernelApp.launch_instance(new NamedArgument("kernel_class", kernel)); } Ok wasn't that hard, chmod +x ./a.ts && ./a.ts NOTE: When using the `ipython kernel` entry point, Ctrl-C will not work.

For some reason I wanted to "port" Jupyter Echo Kernel to Deno using deno-python. Ok we're comparing something, lets check what it is, arguments are passed in linux x86 in rdi then rsi The bug is there though, can you spot it .... After I asked around (deno discord have a couple of ffi magicians there) I have my answer:

Get the Android app

Or read this on Hacker News

Read more on:

Photo of python

python

Photo of Debugging Story

Debugging Story

Related news:

News photo

Timezone-naive datetimes are one of the most dangerous objects in Python

News photo

Leaked admin access token to Python, PyPI, and PSF GitHub repos

News photo

Jurigged: Hot Reloading for Python