Calysto / metakernel

Jupyter/IPython Kernel Tools

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example needed for stdin in Wrapper

dsblank opened this issue · comments

@blink1073 I'm trying to figure out how a kernel, say bash, can get input from the user. For example, I'd like to write a Java program that when run from the shell would be able to get input from the user and route that back to the program. Do we have what it takes to do that? I see that are stdin prompts and a stdin_handler, but I don't see an example.

The Octave kernel provides stdin by overrriding raw_input: https://github.com/Calysto/octave_kernel/blob/master/octave_kernel/kernel.py#L119. By calling super(), the standard input() behavior of the ipykernel is invoked.

Thanks! Could that method be moved into ProcessMetaKernel? Would that allow all derived class to get stdin handling?

The method is on the Kernel base class.

I mean: should we move that specific code from OctaveKernel.raw_input method to ProcessMetaKernel.raw_input? It seems that that is exactly what we want for all ProcessMetaKernel-based kernels.

Ah, I see. That is already handled in process metakernel here. The only reason Octave kernel subclasses it is to affect what goes into the prompt.

Ok, can you provide an example of how to get user input from, say, metakernel_bash (which is a ProcessMetaKernel)? I have tried echoing a few things thinking that that would trigger the hook, but haven't been successful. Any pointers appreciated!

It is entirely dependent on the language to produce a STDIN prompt in its repl. In Octave I had to manually override it's input methods to produce the desired regex.

I see where I was having problems: the only kernel in Calysto that actually uses the ProcessMetakernel is Octave. Our own metakernel_bash magic doesn't use it (we define a BashKernel, but don't use it), and so all the ProcessMetekernel enhancements aren't used there.