Kernel cancelling a `input_request` at the end of the execution of a cell

59 views Asked by At

I'm implementing a new Go kernel, using directly the ZMQ messages. But as an extra I want it to execute any bash command when a line is prefixed with !, similar to the usual ipython kernel.

One of the tricky parts seems to be bash scripts that take input -- there is no way (that I know of) to predict when I need to request input. So I took the following approach:

  • Whenever I execute a bash script, if it hasn't ended after 500ms (configurable), it issues an input_request.
  • If the kernel receives any input back (input_reply message), it writes the contents to the bash program's piped stdin (concurrently, not to block), and immediately issues another input_request.

Now at the end of the execution of the bash program, there is always the last input_request pending, and the corresponding widget expecting input from the user.

Jupyter doesn't drop the input_request after the execution of the cell ended, and requires the user to type enter and send an input_reply before another cell can be executed. It complains with "Cell not executed due to pending input"

Is there a way to cancel the input_request (the pending input) if the execution of the last cell already finished ?

Maybe there is some undocumented message that can be send once the bash program ends ?

Any other suggested approach ?

I know something similar works in colab.research.google.com, if I do:

!while read ii; do if [[ "${ii}" == "done" ]] ; then exit 0; fi ; echo "Input: $ii"; done

It correctly asks for inputs, and closes the last one. But I'm not sure how that is achieved.

Jupyter's ipython notebook doesn't seem to have that smarts though, at least here the line above just locks. I suppose it never sends a input_request message.

many thanks in advance!

0

There are 0 answers